算法
文章平均质量分 77
mc46790090
这个作者很懒,什么都没留下…
展开
-
[leetcode]Unique Binary Search Trees
新博文地址:[leetcode]Unique Binary Search Treeshttp://oj.leetcode.com/problems/unique-binary-search-trees/Given n, how many structurally unique BST's (binary search trees) that store values 1...n? Fo...原创 2014-04-30 15:35:47 · 69 阅读 · 0 评论 -
[leetcode]Search Insert Position
新博文地址:[leetcode]Search Insert Positionhttp://oj.leetcode.com/problems/search-insert-position/ Given a sorted array and a target value, return the index if the target is found. If not, return t...原创 2014-04-30 16:24:38 · 69 阅读 · 0 评论 -
[leetcode]Populating Next Right Pointers in Each Node
新博文地址:[leetcode]Populating Next Right Pointers in Each Nodehttp://oj.leetcode.com/problems/populating-next-right-pointers-in-each-node/Given a binary tree struct TreeLinkNode { TreeLinkNode *le...原创 2014-04-30 17:51:41 · 68 阅读 · 0 评论 -
[leetcode]Merge Two Sorted Lists
新博文地址:[leetcode]Merge Two Sorted Listshttp://oj.leetcode.com/problems/merge-two-sorted-lists/Merge two sorted linked lists and return it as a new list. The new list should be made by splicing to...原创 2014-05-02 15:23:47 · 82 阅读 · 0 评论 -
[leetcode]Balanced Binary Tree
新博文地址:[leetcode]Balanced Binary Tree http://oj.leetcode.com/problems/balanced-binary-tree/Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tre...原创 2014-05-02 15:58:07 · 69 阅读 · 0 评论 -
[leetcode]Pascal's Triangle
新博文地址:[leetcode]Pascal's Triangle http://oj.leetcode.com/problems/pascals-triangle/ Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1],...原创 2014-05-03 01:18:04 · 79 阅读 · 0 评论 -
[leetcode]Single Number II
新博文地址:[leetcode]Single Number IIhttp://oj.leetcode.com/problems/single-number-ii/Given an array of integers, every element appears three times except for one. Find that single one.Note:Your alg...原创 2014-05-03 23:57:07 · 72 阅读 · 0 评论 -
[leetcode]Merge Sorted Array
新博文地址:[leetcode]Merge Sorted Arrayhttp://oj.leetcode.com/problems/merge-sorted-array/ Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume that A h...原创 2014-05-04 10:58:13 · 66 阅读 · 0 评论 -
[leetcode]Symmetric Tree
这个方法略2,新博文地址:[leetcode]Symmetric Treehttp://oj.leetcode.com/problems/symmetric-tree/ 写道Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For exam...原创 2014-05-04 16:01:46 · 45 阅读 · 0 评论 -
[leetcode]Swap Nodes in Pairs
新博文地址:[leetcode]Swap Nodes in Pairshttp://oj.leetcode.com/problems/swap-nodes-in-pairs/ Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3...原创 2014-05-04 17:24:54 · 66 阅读 · 0 评论 -
[leetcode]Roman to Integer
http://oj.leetcode.com/problems/roman-to-integer/Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999. 题中大意为返回罗马数字(字符串)对应的整数。我的想法很简单,逐位计算。...原创 2014-05-04 22:22:49 · 67 阅读 · 0 评论 -
[leetcode]Count and Say
新博文地址:[leetcode]Count and Say第二遍使用了dfs算法,代码相对稍稍简洁了一丢丢,基本差不多,思想也相仿http://oj.leetcode.com/problems/count-and-say/The count-and-say sequence is the sequence of integers beginning as follows:1, 11...原创 2014-05-04 23:11:39 · 98 阅读 · 0 评论 -
[leetcode]Gray Code
两种思路,详情请参考新博文地址:[leetcode]Gray Codehttp://oj.leetcode.com/problems/gray-code/ The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative ...原创 2014-05-05 13:10:54 · 82 阅读 · 0 评论 -
[leetcode]Add Binary
这个算法太。。蛋疼了,新博文地址:[leetcode]Add Binary http://oj.leetcode.com/problems/add-binary/Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100". 刚开...原创 2014-05-05 21:33:17 · 53 阅读 · 0 评论 -
[leetcode]Remove Duplicates from Sorted List II
新博文地址:[leetcode]Remove Duplicates from Sorted List IIhttp://oj.leetcode.com/problems/remove-duplicates-from-sorted-list-ii/ Given a sorted linked list, delete all nodes that have duplicate num...原创 2014-05-06 11:02:04 · 89 阅读 · 0 评论 -
[leetcode]Linked List Cycle II
新博文地址:[leetcode]Linked List Cycle II http://oj.leetcode.com/problems/linked-list-cycle-ii/ Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Fol...原创 2014-05-07 11:14:43 · 75 阅读 · 0 评论 -
[leetcode]3Sum
新博文地址:[leetcode]3Sumhttp://oj.leetcode.com/problems/3sum/Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gi...原创 2014-05-07 15:25:06 · 64 阅读 · 0 评论 -
[leetcode]3Sum Closest
新博文地址[leetcode]3Sum Closesthttp://oj.leetcode.com/problems/3sum-closest/Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return th...原创 2014-05-07 21:19:15 · 59 阅读 · 0 评论 -
[leetcode]Longest Palindromic Substring
新博文地址:[leetcode]Longest Palindromic Substringhttp://oj.leetcode.com/problems/longest-palindromic-substring/ Given a string S, find the longest palindromic substring in S. You may assume that t...原创 2014-05-08 15:39:59 · 71 阅读 · 0 评论 -
KMP算法(1)——java实现
这篇博文写的实在是太糟蹋了,请大家移步KMP算法小结,如果未能帮大家解惑,请见谅,并欢迎再新博文下面留言讨论。 KMP是比较知名的一个字符串匹配算法。由D.E.Knuth与V.R.Pratt和J.H.Morris同时发现(不明白什么叫同时发现+_+)因此得名KMP算法。 首先大家想一下字符串如何匹配?比如str1 = “BBC ABCDAB ABCDABCDABDE”,想知...原创 2014-05-10 21:27:57 · 108 阅读 · 0 评论 -
[leetcode]Path Sum
新博文地址:[leetcode]Path SumPath Sum写道Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For exampl...原创 2014-05-11 16:14:17 · 57 阅读 · 0 评论 -
[leetcode]Path Sum II
新博文地址:[leetcode]Path Sum IIPath Sum II Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = ...原创 2014-05-11 16:18:50 · 74 阅读 · 0 评论 -
[leetcode]Minimum Path Sum
Minimum Path SumGiven a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either d...原创 2014-05-11 23:30:58 · 66 阅读 · 0 评论 -
[leetcode]Permutations
新博文地址:[leetcode]PermutationsPermutationsGiven a collection of numbers, return all possible permutations. For example, [1,2,3] have the following permutations: [1,2,3], [1,3,2], [2,1,3], [2,3,1],...原创 2014-05-14 10:52:22 · 74 阅读 · 0 评论 -
[leetcode]Generate Parentheses
新博文地址:[leetcode]Generate Parentheses感觉新写的代码可读性稍稍好点(≧▽≦)/~~(≧▽≦)/~Generate ParenthesesGiven n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For...原创 2014-05-14 15:05:35 · 65 阅读 · 0 评论 -
[leetcode]Merge k Sorted Lists
新博文总结了三种算法,新博文地址:[leetcode]Merge k Sorted ListsMerge k Sorted Lists Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. K路归并,不知道大家对2路归并还有木有印象,...原创 2014-05-14 16:23:51 · 64 阅读 · 0 评论 -
[leetcode]Combinations
新博文地址:[leetcode]CombinationsCombinationsGiven two integers n and k, return all possible combinations of k numbers out of 1 ... n. For example, If n = 4 and k = 2, a solution is: [ [2,4], [3,4],...原创 2014-05-14 17:04:09 · 61 阅读 · 0 评论 -
[leetcode]Subsets
新博文地址:[leetcode]SubsetsSubsetsGiven a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain dupl...原创 2014-05-15 11:10:32 · 51 阅读 · 0 评论 -
[leetcode]Unique Paths
新博文地址:[leetcode]Unique PathsUnique PathsA robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point...原创 2014-05-15 13:56:05 · 58 阅读 · 0 评论 -
[leetcode]Unique Paths II
新博文地址:[leetcode]Unique Paths IIUnique Paths IIFollow up for "Unique Paths": Now consider if some obstacles are added to the grids. How many unique paths would there be? An obstacle and empty spa...原创 2014-05-15 14:19:57 · 58 阅读 · 0 评论 -
[leetcode]Combination Sum
新博文地址:[leetcode]Combination SumCombination Sum 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...原创 2014-05-16 11:33:44 · 57 阅读 · 0 评论 -
[leetcode]Triangle
新博文地址:[leetcode]TriangleTriangleGiven a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following trian...原创 2014-05-22 15:48:45 · 78 阅读 · 0 评论 -
[leetcode]Partition List
新博文地址:Partition List果然出去玩了一个星期回来状态极差。。。。Partition ListGiven 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 pr...原创 2014-05-22 17:47:02 · 69 阅读 · 0 评论 -
[leetcode]Binary Tree Level Order Traversal
新博文地址:[leetcode]Binary Tree Level Order TraversalBinary Tree Level Order Traversal 写道Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, le...原创 2014-05-23 10:27:34 · 91 阅读 · 0 评论 -
[leetcode]Validate Binary Search Tree
新博文地址:[leetcode]Validate Binary Search TreeValidate Binary Search TreeGiven a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree...原创 2014-05-23 11:31:06 · 103 阅读 · 0 评论 -
[leetcode]Binary Tree Level Order Traversal II
新博文地址:[leetcode]Binary Tree Level Order Traversal IIBinary Tree Level Order Traversal II 写道Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from l...原创 2014-05-23 23:09:08 · 80 阅读 · 0 评论 -
[leetcode]N-QueensII
新博文地址:[leetcode]N-QueensIIN-Queens IIFollow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions. 八皇后问题,返回解的个数,比返回解的情况还要简单,这个问题...原创 2014-05-24 00:10:17 · 81 阅读 · 0 评论 -
[leetcode]Binary Tree Postorder Traversal
新博文地址:[leetcode]Binary Tree Postorder TraversalBinary Tree Postorder Traversal Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3...原创 2014-05-24 00:23:09 · 76 阅读 · 0 评论 -
[leetcode]N-Queens
新博文地址:[leetcode]N-QueensN-Queens 写道The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all dist...原创 2014-05-24 14:11:09 · 53 阅读 · 0 评论 -
[leetcode]Pascal's Triangle II
新博文地址:[leetcode]Pascal's Triangle IIPascal's Triangle IIGiven an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algor...原创 2014-05-24 14:40:07 · 72 阅读 · 0 评论