
leetcode
conniemessi
这个作者很懒,什么都没留下…
展开
-
LeetCode解题报告 169. Majority Element [easy]
题目描述Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majorit原创 2016-09-13 00:16:37 · 300 阅读 · 0 评论 -
LeetCode解题报告 112. Path Sum [easy]
题目要求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 example:Given the below binary tre原创 2017-01-03 11:13:01 · 297 阅读 · 0 评论 -
LeetCode解题报告 445. Add Two Numbers II [medium]
题目描述You are given two linked lists representing two non-negative numbers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and return it原创 2016-12-23 00:07:57 · 775 阅读 · 0 评论 -
LeetCode解题报告 344. Reverse String [easy]
题目要求Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".解题思路逆转一个字符串,注意空格就行。复杂度分析时间复杂度O(n)。代码如下:cla原创 2016-12-23 01:02:06 · 296 阅读 · 0 评论 -
LeetCode解题报告 383. Ransom Note [easy]
题目描述Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the maga原创 2016-12-23 01:05:13 · 250 阅读 · 0 评论 -
LeetCode解题报告 199. Binary Tree Right Side View [medium]
题目描述Given 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.For example:Given the following binary tre原创 2016-12-24 00:39:02 · 292 阅读 · 0 评论 -
LeetCode解题报告 108. Convert Sorted Array to Binary Search Tree [medium]
题目描述Given an array where elements are sorted in ascending order, convert it to a height balanced BST.解题思路题目要求对一个已经排好序的数组来构造一颗平衡二叉树。平衡二叉树指的是对于树上任意一个节点,其左右子树的高度差不超过1。若两颗子树节点数量相同,且使用同原创 2016-12-20 00:44:38 · 229 阅读 · 0 评论 -
LeetCode解题报告 107. Binary Tree Level Order Traversal II [easy]
题目要求Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree [3,9,20,n原创 2017-01-04 20:36:06 · 264 阅读 · 0 评论 -
LeetCode解题报告 111. Minimum Depth of Binary Tree [easy]
题目要求Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.解题思路找二叉树的最短路径。和我之前做的原创 2017-01-04 21:20:00 · 321 阅读 · 0 评论 -
LeetCode解题报告 110. Balanced Binary Tree [easy]
题目要求Given 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 n原创 2017-01-04 22:11:39 · 298 阅读 · 0 评论 -
LeetCode解题报告 257. Binary Tree Paths [easy]
题目要求Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]原创 2017-01-04 23:21:56 · 257 阅读 · 0 评论 -
LeetCode解题报告 322. Coin Change [medium]
题目描述You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount原创 2017-01-05 14:38:56 · 344 阅读 · 0 评论 -
LeetCode解题报告 309. Best Time to Buy and Sell Stock with Cooldown[medium]
有限状态机三个状态f0[i]:第i天过后处于状态0时的最大收益f1[i]:第i天过后处于状态1时的最大收益f2[i]:第i天过后处于状态2时的最大收益f0[1]=0f1[1]=-1 买进来还没有卖掉f2[1]=负无穷i>1时:f0[i]=max(f0[i-1],f2[i-1])f1[i]=max( f1[i-1], f0[i-1]原创 2016-10-26 21:00:36 · 326 阅读 · 0 评论 -
LeetCode解题报告 399. Evaluate Division [medium]
题目要求Equations are given in the format A / B = k, where A and B are variables represented as strings, and k is a real number (floating point number). Given some queries, return the answers.原创 2017-01-06 09:09:43 · 516 阅读 · 0 评论 -
LeetCode解题报告 452. Minimum Number of Arrows to Burst Balloons [medium]
题目描述There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the horizontal diameter. Since it's horizontal, y原创 2016-12-18 01:02:21 · 389 阅读 · 0 评论 -
LeetCode解题报告 394. Decode String [medium]
题目描述Given 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原创 2016-12-20 10:03:55 · 290 阅读 · 0 评论 -
LeetCode解题报告 406. Queue Reconstruction by Height [medium]
题目描述Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person and k is the number of people in原创 2017-01-07 18:07:39 · 457 阅读 · 0 评论 -
LeetCode解题报告 55. Jump Game [medium]
题目描述Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.原创 2016-12-30 15:06:15 · 240 阅读 · 0 评论 -
LeetCode解题报告 96. Unique Binary Search Trees [medium]
题目要求Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2原创 2017-01-02 23:48:10 · 380 阅读 · 0 评论 -
LeetCode解题报告 279. Perfect Squares [medium]
题目描述Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.For example, given n = 12, return 3 because 12 = 4 + 4 + 4;原创 2016-12-17 00:52:52 · 624 阅读 · 0 评论 -
LeetCode解题报告 6. ZigZag Conversion[easy]
题目描述The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H原创 2016-09-06 15:33:24 · 395 阅读 · 0 评论 -
LeetCode解题报告 53. Maximum Subarray [medium]
题目描述Find the contiguous subarray within an array (containing at least one number) which has the largest sum.Example: given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous subarray [4,-1,2原创 2016-09-17 00:13:30 · 283 阅读 · 0 评论 -
LeetCode解题报告 70. Climbing Stairs [easy]
题目描述You 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?解题思路题目意思原创 2016-10-21 11:52:26 · 448 阅读 · 0 评论 -
LeetCode解题报告 338. Counting Bits [medium]
题目描述Given 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.Example:F原创 2016-10-21 13:28:16 · 521 阅读 · 0 评论 -
LeetCode解题报告 101. Symmetric Tree [easy]
题目描述Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3原创 2016-10-13 13:30:28 · 275 阅读 · 0 评论 -
LeetCode解题报告 413. Arithmetic Slices [medium]
题目描述A 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 arithmet原创 2016-10-26 14:01:41 · 503 阅读 · 0 评论 -
LeetCode解题报告 357. Count Numbers with Unique Digits [medium]
题目描述Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x n.Example:Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x [11原创 2016-10-26 14:58:30 · 256 阅读 · 0 评论 -
LeetCode解题报告 122. Best Time to Buy and Sell Stock II [medium]
题目描述Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie原创 2016-11-07 11:49:19 · 269 阅读 · 0 评论 -
LeetCode解题报告 343. Integer Break [medium]
题目描述Given 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.For example, given n = 2, return 1 (2 = 1 + 1); given n = 10, return 36 (10 = 3 +原创 2016-10-26 15:44:01 · 321 阅读 · 0 评论 -
LeetCode解题报告 392. Is Subsequence [medium]
题目描述Given 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,原创 2016-10-26 17:09:57 · 308 阅读 · 0 评论 -
LeetCode解题报告 100. Same Tree [easy]
题目描述Given 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.解题原创 2016-10-01 22:14:22 · 292 阅读 · 0 评论 -
LeetCode解题报告 120. Triangle [medium]
题目描述Given 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 triangle[ [2], [原创 2016-12-03 15:07:46 · 374 阅读 · 0 评论 -
LeetCode解题报告 455. Assign Cookies [easy]
题目描述Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum s原创 2016-11-24 23:44:42 · 258 阅读 · 0 评论 -
LeetCode解题报告 104. Maximum Depth of Binary Tree [easy]
题目描述Given 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.解题思路题目要求返回一个二叉树的最大深度。原创 2016-11-25 13:16:54 · 330 阅读 · 0 评论 -
LeetCode解题报告 377. Combination Sum IV [medium]
类似完全背包问题(可重复背包)f[0]=1f[i] 组成和为i的方案数f[i]=求和(f[j-nums[i])(对于示例中的数值: 最后一个为1时,求有多少个组成和为4-1=3的方案数; 最后一个为2时,求有多少个组成和为4-2=2的方案数; 最后一个为3时,求有多少个组成和为4-3=1的方案数;)return f[target]原创 2016-10-26 20:00:17 · 411 阅读 · 0 评论 -
LeetCode解题报告 102. Binary Tree Level Order Traversal [easy]
题目描述Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree [3,9,20,null,null,15,7], 3原创 2016-11-25 21:53:57 · 226 阅读 · 0 评论 -
LeetCode解题报告 241. Different Ways to Add Parentheses [medium]
题目描述Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *.Exa原创 2016-11-27 13:22:49 · 325 阅读 · 0 评论 -
LeetCode解题报告 349. Intersection of Two Arrays [easy]
题目描述Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].Note:Each element in the result must be uniq原创 2016-12-21 00:49:42 · 388 阅读 · 0 评论