Leetcode
文章平均质量分 54
Arcome
这个作者很懒,什么都没留下…
展开
-
LeetCode #77 - Combinations - Medium
ProblemGiven two integers n and k, return all possible combinations of k numbers out of 1 ... n.ExampleFor example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [原创 2016-12-20 08:12:02 · 373 阅读 · 0 评论 -
LeetCode #207 - Course Schedule - Medium
Course Schedule Series Course Schedule I: Course Schedule II: ProblemThere are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example t原创 2016-12-21 20:33:53 · 633 阅读 · 0 评论 -
LeetCode #210 - Course Schedule II - Medium
Course Schedule Series Course Schedule I: http://blog.csdn.net/Arcome/article/details/53790947 Course Schedule II: ProblemThere are a total of n courses you have to take, labeled from 0 to n -原创 2016-12-21 20:36:36 · 450 阅读 · 0 评论 -
LeetCode #329 - Longest Increasing Path in a Matrix - Hard
ProblemGiven an integer matrix, find the length of the longest increasing path.From each cell, you can either move to four directions: left, right, up or down. You may NOT move diagonally or move outs原创 2016-12-21 20:29:58 · 713 阅读 · 0 评论 -
LeetCode #404 - Sum of Left Leaves - Easy
ProblemFind the sum of all left leaves in a given binary tree.Example 3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24.原创 2016-12-15 16:58:09 · 256 阅读 · 0 评论 -
LeetCode #226 - Invert Binary Tree - Easy
ProblemInvert a binary tree.Example 4 / \ 2 7 / \ / \1 3 6 9-> 4 / \ 7 2 / \ / \9 6 3 1Algorithm整理一下题意:翻转一棵二叉树。首先想到的当然是递归解法。对每个节点,都翻转左右子树。代码如下。//递归版本,用时0原创 2016-12-15 16:46:46 · 291 阅读 · 0 评论 -
LeetCode #101 - Symmetric Tree - Easy
ProblemGiven a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).Example this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But t原创 2016-11-12 22:02:54 · 374 阅读 · 0 评论 -
LeetCode #394 - Decode String -Medium
ProblemGiven an encoded string, return it's decoded string.The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is原创 2016-11-12 10:21:42 · 367 阅读 · 0 评论 -
LeetCode #108 - Convert Sorted Array to Binary Search Tree -Medium
ProblemGiven an array where elements are sorted in ascending order, convert it to a height balanced BST.ExampleInput:[1,2,3]Output: 1 /\ 2 3Algorithm整理一下题意:给定一个升序数组,要求将其转化为一课平衡二叉树经典的树类型题目。采原创 2016-11-12 00:16:00 · 324 阅读 · 0 评论 -
LeetCode #337 - House Robber III - Medium
ProblemThe thief has found himself a new place for his thievery again. There is only one entrance to this area, called the "root." Besides the root, each house has one and only one parent house. After原创 2016-11-09 18:54:04 · 388 阅读 · 0 评论 -
LeetCode #94 - Binary Tree Inorder Traversal - Medium
ProblemGiven a binary tree, return the inorder traversal of its nodes' values.Note: Recursive solution is trivial, could you do it iteratively?ExampleGiven binary tree [1,null,2,3], 1 \ 2原创 2016-12-15 17:04:51 · 245 阅读 · 0 评论 -
LeetCode #145 - Binary Tree Postorder Traversal - Hard
相似题目: 二叉树的前序遍历:http://blog.csdn.net/Arcome/article/details/53672912 二叉树的中序遍历:http://blog.csdn.net/arcome/article/details/53672748 二叉树的后序遍历:ProblemGiven a binary tree, return the postorder trav原创 2016-12-19 15:32:14 · 340 阅读 · 0 评论 -
LeetCode #144 - Binary Tree Preorder Traversal - Medium
相似题目: 二叉树的前序遍历:http://blog.csdn.net/arcome/article/details/53672748 二叉树的中序遍历: 二叉树的后序遍历:ProblemGiven a binary tree, return the preorder traversal of its nodes' values.Note: Recursive solution原创 2016-12-15 17:12:39 · 360 阅读 · 0 评论 -
LeetCode #89 - Gray Code - Medium
ProblemThe gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence o原创 2016-12-20 08:07:58 · 370 阅读 · 0 评论 -
LeetCode #46 - Permutations - Medium
Permutations Series Permutations I: Permutations II: ProblemGiven a collection of distinct numbers, return all possible permutations.Example[1,2,3] have the following permutations:[ [1,2,3原创 2016-12-20 08:03:56 · 373 阅读 · 0 评论 -
LeetCode #22 - Generate Parentheses - Medium
ProblemGiven n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.Examplegiven n = 3, a solution set is:[ "((()))", "(()())", "(())()", "()(())",原创 2016-12-20 08:00:20 · 436 阅读 · 0 评论 -
LeetCode #357 - Count Numbers with Unique Digits - Medium
ProblemGiven a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n.Hints:A direct way is to use the backtracking approach.Backtracking should contains three states whi原创 2016-12-19 18:56:38 · 285 阅读 · 0 评论 -
LeetCode #235 - Lowest Common Ancestor of a Binary Search Tree Easy
ProblemGiven a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: The lowest common ancestor is defined be原创 2016-12-19 18:37:46 · 305 阅读 · 0 评论 -
LeetCode #39 - Combination Sum - Medium
Combination Sum Series Combination Sum I: Combination Sum II: Combination Sum III: http://blog.csdn.net/Arcome/article/details/53758448ProblemGiven a set of candidate numbers (C) (without原创 2016-12-26 20:05:22 · 425 阅读 · 0 评论 -
LeetCode #216 - Combination Sum III - Medium
Combination Sum Series Combination Sum I: Combination Sum II: Combination Sum III: ProblemFind all possible combinations of k numbers that add up to a number n, given that only numbers f原创 2016-12-20 07:56:49 · 657 阅读 · 0 评论 -
LeetCode #90 - Subsets II - Medium
Subsets Series Subsets I: http://blog.csdn.net/arcome/article/details/53888806 Subsets II: ProblemGiven a collection of integers that might contain duplicates, nums, return all possible subsets原创 2016-12-26 20:01:22 · 445 阅读 · 0 评论 -
LeetCode #78 - Subsets - Medium
ProblemGiven a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.ExampleFor example,If nums = [1,2,3], a solution is:[ [3], [1原创 2016-12-26 19:55:34 · 447 阅读 · 0 评论 -
LeetCode #100 - Same Tree - Easy
ProblemGiven two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.ExampleDete原创 2016-11-09 18:36:25 · 379 阅读 · 0 评论 -
LeetCode #104 - Maximum Depth of Binary Tree - Easy
ProblemGiven a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Subscribe to see which companies ask原创 2016-11-07 21:40:31 · 745 阅读 · 0 评论 -
LeetCode #357 - Count Numbers with Unique Digits - Medium
ProblemGiven a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n.Hint:A direct way is to use the backtracking approach.Backtracking should contains three states whic原创 2016-11-02 08:10:05 · 368 阅读 · 0 评论 -
LeetCode #116 - Populating Next Right Pointers in Each Node - Medium
ProblemGiven a binary treestruct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next;}Populate each next pointer to point to its next right node. If there is no next right原创 2016-11-12 21:54:06 · 365 阅读 · 0 评论 -
LeetCode #413 - Arithmetic Slices - Medium
ProblemA sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.For example, these are arithmetic原创 2016-11-01 23:22:46 · 583 阅读 · 0 评论 -
LeetCode #392 - Is Subsequence - Medium
ProblemGiven a string s and a string t, check if s is subsequence of t.You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 500,000) str原创 2016-11-01 23:39:19 · 377 阅读 · 0 评论 -
LeetCode #199 - Binary Tree Right Side View - Medium
ProblemGiven a binary tree, imagine yourself standing on the right side of it,return the values of the nodes you can see ordered from top to bottom.Example 1 <--- / \2 3原创 2016-11-12 21:35:44 · 368 阅读 · 0 评论 -
Leetcode #338 - Counting bits - Medium
ProblemGiven a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.ExampleFor num = 5 y原创 2016-10-25 17:46:48 · 436 阅读 · 0 评论 -
Leetcode #70 - Climbing Stairs - Easy
ProblemYou are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Exampleinput:1output:1Algor原创 2016-10-25 08:43:04 · 455 阅读 · 0 评论 -
Leetcode #1 - Two Sum - Easy
ProblemGiven an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.The return format h原创 2016-09-13 08:55:21 · 316 阅读 · 0 评论 -
LeetCode #377 - Combination Sum IV - Medium
ProblemGiven an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target.Examplenums = [1, 2, 3]target = 4The poss原创 2016-11-03 09:40:05 · 336 阅读 · 0 评论 -
LeetCode #343 - Integer Break - Medium
ProblemGiven a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.Note: You may assume that n原创 2016-11-02 08:49:43 · 343 阅读 · 0 评论 -
LeetCode #223 - Rectangle Area - Easy
ProblemFind the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Assume that the total area原创 2016-12-14 17:41:07 · 448 阅读 · 0 评论 -
LeetCode #396 - Rotate Function - Easy
ProblemGiven an array of integers A and let n to be its length.Assume Bk to be an array obtained by rotating the array A k positions clock-wise, we define a "rotation function" F on A as follow:F(k) =原创 2016-12-14 20:58:25 · 302 阅读 · 0 评论 -
LeetCode #110 - Balanced Binary Tree - Easy
ProblemGiven a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never dif原创 2016-11-12 22:04:34 · 425 阅读 · 0 评论 -
LeetCode #173 - Binary Search Tree Iterator - Medium
ProblemImplement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the BST.Note: next()原创 2016-12-16 18:07:38 · 311 阅读 · 0 评论 -
LeetCode #437 - Path Sum III - Medium
ProblemYou are given a binary tree in which each node contains an integer value.Find the number of paths that sum to a given value.The path does not need to start or end at the root or a leaf, but it m原创 2016-12-16 18:02:27 · 395 阅读 · 0 评论 -
LeetCode #230 - Kth Smallest Element in a BST - Medium
ProblemGiven 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 ≤ k ≤ BST's total elements.Follow up:What if the BST i原创 2016-12-16 17:59:43 · 278 阅读 · 0 评论