
算法
文章平均质量分 62
To-Big_Fish
爱编程,爱运动,爱游戏。。。
展开
-
词语提取小工具开放啦
推荐一个词语提取小工具给大家使用,免费的。华为云的云搜索服务,可以自定义自己的词库来做分词、停词。修改词库还可以热更新,不用重启即可生效。大家都知道词库中的词从哪里来,哪些才是有用的词,这是让人头疼的事情。每天苦读海量文章,也才能从中找出几个自己认为还不错的词。其实:数据!词语不就是在数据中!这里有一个词语提取小工具可以提取词语。下面,我们一起看看怎么使用他的小工具的。第一步,找到一篇最近大火的复...原创 2018-04-23 19:32:45 · 5908 阅读 · 2 评论 -
Rotate Image 数组顺时针旋转90度
给定一个n*n数组,求顺时针旋转之后的数组,不能用到原创 2014-11-19 20:13:55 · 1640 阅读 · 0 评论 -
顺时针打印矩阵
顺时针打印矩阵Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9原创 2015-01-21 19:44:54 · 1019 阅读 · 0 评论 -
Reverse Linked List II leetcode
Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n satisfy the原创 2014-12-16 09:26:13 · 933 阅读 · 0 评论 -
Add Two Numbers leetcode
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link原创 2014-12-31 19:45:36 · 777 阅读 · 0 评论 -
Insertion Sort List leetcode
连用插入排序法将链表排序为了方便,只定义一个头节点。思路:定义头结点 result 令 result->next =head , 然后将链表中的值一一取出来,然后插入到合适的位置 插入之前要先断开链表 新链表刚开始只有一个元素 head令p=head->next p往后遍历, 将p的值插入到合适的新链表中原创 2014-12-29 22:19:25 · 764 阅读 · 0 评论 -
Intersection of Two Linked Lists leetcode
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘原创 2014-12-29 21:42:33 · 858 阅读 · 0 评论 -
Sort List leetcode
实现单链表排序 时间复杂度要求为 nlogn 由于是单链表,用快速排序无法往前面遍历(双向链表可以考虑),这里我们用到归并排序代码如下:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(in原创 2014-12-10 22:10:08 · 878 阅读 · 0 评论 -
Reverse Integer leetcode
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Have you thought about this?Here are some good questions to ask before c原创 2015-01-15 21:15:02 · 846 阅读 · 0 评论 -
Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?题目的意思是判断链表中有没有环思路:定义两个指针,一个慢指针,一个快指针,慢指针一次走两步,快指针一次走一步,如果有环,那么慢、快指针一原创 2014-12-26 20:01:45 · 712 阅读 · 0 评论 -
Roman to Integer leetcode
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.题目的意思是将给定的罗马数字转换为一个整数什么是罗马数字:I, II, III, IV, V, VI, VII, VIII, IX, X.原创 2015-01-15 20:00:58 · 670 阅读 · 0 评论 -
二叉搜索树的后序遍历序列
给定一个序列,判断该序列是不是二叉搜索树的后序遍历序列二叉搜索树定义:二叉查找树(英语:Binary Search Tree),也称二叉搜索树、有序二叉树(英语:ordered binary tree),排序二叉树(英语:sorted binary tree),是指一棵空树或者具有下列性质的二叉树:1、若任意节点的左子树不空,则左子树上所有结原创 2015-01-23 21:36:32 · 1149 阅读 · 0 评论 -
判断一个序列是否是栈的弹出序列
给定两个序列,判断后一个序列是否是第一个序列入栈的出栈顺序学习过在数据结构的人肯定遇到过很多这种题目 比如给定一个序列 如 1 2 3 4 5的入栈序列 问 4 5 3 2 1是不是前者的一个出栈序列思路首先看 出栈序列 4 5 3 2 1 第一个元素是4 也就是说入栈时 必须要先找到4 然后出栈在继续找 5 ,可以原创 2015-01-22 21:24:14 · 1422 阅读 · 0 评论 -
Minimum Size Subarray Sum -- leetcode
题目描述:Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn’t one, return 0 instead.For example, given the array [2,3,1原创 2015-06-02 21:26:42 · 908 阅读 · 0 评论 -
Leetcode Shortest Palindrome (最短回文串)
Leetcode Shortest Palindrome (最短回文串)题目描述Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindro原创 2015-07-24 21:28:21 · 4795 阅读 · 1 评论 -
Letter Combinations of a Phone Number
Letter Combinations of a Phone Number题目如下:Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (jus原创 2015-08-14 15:41:12 · 697 阅读 · 0 评论 -
Dungeon Game
Dungeon Game题目The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our v原创 2015-08-26 08:56:57 · 1137 阅读 · 0 评论 -
House Robber && House RobberⅡ
House Robber && House RobberⅡHouse Robber You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint原创 2015-08-28 11:36:33 · 924 阅读 · 0 评论 -
Word Search 和 Word Search Ⅱ
Word Search 和 Word Search ⅡWord SearchGiven a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, whe原创 2015-08-28 21:22:42 · 1639 阅读 · 0 评论 -
Word Break && Word Break II
Word Break && Word Break IIWord Break题目:Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more原创 2015-08-26 21:39:14 · 1472 阅读 · 0 评论 -
Lowest Common Ancestor of a Binary Search Tree
Lowest Common Ancestor of a Binary Search Tree题目:在二叉查找树中给定两个点p,q,求p,q的最低公共父节点,p,q可以是父子关系Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nod原创 2015-08-26 16:05:45 · 812 阅读 · 0 评论 -
Kth Largest Element in an Array
Kth Largest Element in an Array题目:找到数组中第K大的数Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinc原创 2015-08-26 19:36:32 · 2047 阅读 · 0 评论 -
Kth Smallest Element in a BST
Kth Smallest Element in a BST题目如下:Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1原创 2015-08-25 17:01:08 · 822 阅读 · 0 评论 -
Count and Say --leetcode
Count and Say --leetcode题目如下The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is rea原创 2015-08-25 11:28:42 · 697 阅读 · 0 评论 -
Partition List leetcode
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of原创 2014-12-25 21:37:02 · 843 阅读 · 0 评论 -
Merge k Sorted Lists leetcode
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.题目的意思是将k个有序链表合并成一个有序链表思路:利用归并排序,图解如下:只不过在k链表合并中,图中的10 4 6 等元素变为了链表,需要 mergeTwoList(A,原创 2014-12-26 09:56:17 · 798 阅读 · 0 评论 -
Minimum Window Substring leetcode
Minimum Window SubstringGiven a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T =原创 2014-12-08 21:50:53 · 978 阅读 · 0 评论 -
Remove Duplicates from Sorted Array(去掉重复的元素)leetcode
题意如下:对于给定的数组:1原创 2014-11-18 10:38:57 · 738 阅读 · 0 评论 -
计算字符串的相似度
字符串相似度计算是查找两个字符串的公共子串,利用公共子串的长度根据相应的公式来衡量两个字符串的相似程度。原创 2014-10-10 11:12:33 · 1478 阅读 · 0 评论 -
Container With Most Water (求两条线和x轴能够围城最大面积)
有一个数组 num[]原创 2014-11-12 15:05:46 · 954 阅读 · 0 评论 -
Combination Sum(leetcode)
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited nu原创 2014-11-12 21:22:57 · 618 阅读 · 0 评论 -
求二维数组矩形区域最大和问题
求二维数组矩形区域最大和问题对于一个二维数组原创 2014-09-30 10:48:50 · 3688 阅读 · 0 评论 -
找到数组中第一个不见的正整数(First Missing Positive )
给定一个数组 A[]y原创 2014-11-11 22:05:08 · 1028 阅读 · 0 评论 -
求数组中最长的连续序列(Longest Consecutive Sequence )
给定一组数据4,7,8,1,2,3那么数组中的原创 2014-11-11 21:05:28 · 3175 阅读 · 0 评论 -
求连续子数组的最大乘积
很多人肯定都做过求连续子数组的最大和问题,相信大多数人都很容易将代码原创 2014-11-10 19:47:13 · 1745 阅读 · 0 评论 -
求最大公约数问题
今天看了编程之美中的求解最大公约原创 2014-09-23 20:10:34 · 804 阅读 · 0 评论 -
堆排序中建堆时间复杂度
如果仅从代码上直观观察,会得出构造二叉堆的时间复杂度为O(n㏒n)的结果,这个结果是错的,虽然该算法外层套一个n次循环,而内层套一个分治策略下的㏒n复杂度的循环,该思考方法犯了一个原则性错误,那就是构建二叉堆是自下而上的构建,每一层的最大纵深总是小于等于树的深度的,因此,该问题是叠加问题,而非递归问题。那么换个方式,假如我们自上而下建立二叉堆,那么插入每个节点都和树的深度有关,并且都是不断的把树折原创 2014-05-29 20:16:16 · 2499 阅读 · 0 评论 -
判断单链表中是否有环,如果有环则找到环的入口地址
第一种方法是从单链表head开始,每遍历一个,就把那个node放在hashset里,走到下一个的时候,把该node放在hashset里查找,如果有相同的,就表示有环,如果走到单链表最后一个node,在hashset里都没有重复的node,就表示没有环。 这种方法需要O(n)的空间和时间。 第二种方法是设置两个指针指向单链表的head, 然后开始遍历,第一个指针走一步,第二个原创 2014-11-04 21:15:29 · 2001 阅读 · 0 评论 -
求连续向量的最大子和问题(扫描算法)
问题来自《编程珠玑》这本书,我记得以前考研的时候模拟题目中也有过lei'xi原创 2014-06-11 21:44:27 · 882 阅读 · 0 评论 -
Reverse Nodes in k-Group leetcode
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is原创 2014-12-15 21:40:31 · 733 阅读 · 0 评论