leetcode
_yxy_
没有什么解决不了的问题,努力就好!
展开
-
LeetCode 236. Lowest Common Ancestor of a Binary Tree
题目链接:https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/#/description题目描述:Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.Accor原创 2017-06-02 18:48:35 · 158 阅读 · 0 评论 -
LeetCode 102. Binary Tree Level Order Traversal 和107
LeetCode102. Binary Tree Level Order Traversal题目链接:https://leetcode.com/problems/binary-tree-level-order-traversal/?tab=Description题目描述:Given a binary tree, return the level order traversal原创 2017-02-21 21:14:44 · 205 阅读 · 0 评论 -
LeetCode 111. Minimum Depth of Binary Tree
题目链接:https://leetcode.com/problems/minimum-depth-of-binary-tree/?tab=Description题目描述:Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest原创 2017-02-18 11:30:51 · 167 阅读 · 0 评论 -
LeetCode 112. Path Sum
题目链接:https://leetcode.com/problems/path-sum/?tab=Description题目描述: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原创 2017-02-18 11:26:07 · 159 阅读 · 0 评论 -
LeetCode 257. Binary Tree Paths
题目链接:https://leetcode.com/problems/binary-tree-paths/?tab=Description题目描述:Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \原创 2017-02-18 11:19:34 · 169 阅读 · 0 评论 -
LeetCode 104. Maximum Depth of Binary Tree
题目链接:https://leetcode.com/problems/maximum-depth-of-binary-tree/?tab=Description题目描述:Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the long原创 2017-02-18 11:13:49 · 181 阅读 · 0 评论 -
leetcode 100.Same Tree
用深度优先遍历两个二叉树,比较对应节点的值方法一:字节一开始写的,最直接的方法/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : va原创 2017-02-18 10:55:22 · 198 阅读 · 0 评论 -
leetcode 101. Symmetric Tree
题目链接: https://leetcode.com/problems/symmetric-tree/?tab=Description题目描述:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this原创 2017-02-18 11:03:16 · 177 阅读 · 0 评论 -
357. Count Numbers with Unique Digits
题目链接:https://leetcode.com/problems/count-numbers-with-unique-digits/题目描述:Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x n.Example:Given n = 2, retur原创 2016-11-02 20:31:35 · 231 阅读 · 0 评论 -
20. Valid Parentheses
题目链接:https://leetcode.com/problems/valid-parentheses/题目描述:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The bracke原创 2016-11-16 20:38:13 · 152 阅读 · 0 评论 -
22. Generate Parentheses
题目链接:https://leetcode.com/problems/generate-parentheses/题目描述:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3原创 2016-11-16 19:45:15 · 197 阅读 · 0 评论 -
LeetCode 53. Maximum Subarray(dynamic programming)
题目链接:https://leetcode.com/problems/maximum-subarray/题目描述:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the arra原创 2016-09-06 19:09:31 · 348 阅读 · 0 评论 -
Leetcode 227. Basic Calculator II
题目链接:https://leetcode.com/problems/basic-calculator-ii/#/description题目描述:mplement a basic calculator to evaluate a simple expression string.The expression string contains only non-negative原创 2017-03-21 15:55:57 · 258 阅读 · 0 评论 -
leetcode 61.Rotate List
题目链接:https://leetcode.com/problems/rotate-list/题目描述:Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,retu原创 2016-08-18 20:31:25 · 232 阅读 · 0 评论 -
LeetCode 173. Binary Search Tree Iterator
题目链接:https://leetcode.com/problems/binary-search-tree-iterator/#/description题目描述:Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of原创 2017-06-02 16:53:43 · 189 阅读 · 0 评论 -
LeetCode 199. Binary Tree Right Side View
题目链接:https://leetcode.com/problems/binary-tree-right-side-view/#/description题目描述:Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can原创 2017-05-27 21:44:00 · 162 阅读 · 0 评论 -
LeetCode 575. Distribute Candies
题目链接:https://leetcode.com/problems/distribute-candies/#/description题目描述:Given an integer array with even length, where different numbers in this array represent different kinds of candies. Eac原创 2017-05-27 15:51:00 · 265 阅读 · 0 评论 -
LeetCode 572. Subtree of Another Tree
Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a node in s and all of this no原创 2017-05-27 15:46:48 · 657 阅读 · 0 评论 -
LeetCode 75. Sort Colors
题目链接:https://leetcode.com/problems/sort-colors/题目描述:Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the o原创 2016-09-11 19:09:29 · 168 阅读 · 0 评论 -
LeetCode 230. Kth Smallest Element in a BST
题目链接:https://leetcode.com/problems/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 assu原创 2016-08-26 16:29:16 · 357 阅读 · 0 评论 -
LeetCode 229. Majority Element II ,169. Majority Element
题目链接:https://leetcode.com/problems/majority-element-ii/题目描述:Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time原创 2016-08-24 21:29:55 · 378 阅读 · 0 评论 -
LeetCode K sum问题总结
烟客旅人 sigmainfy — http://tech-wonderland.net/blog/summary-of-ksum-problems.html前言:做过leetcode的人都知道, 里面有2sum, 3sum(closest), 4sum等问题, 这些也是面试里面经典的问题, 考察是否能够合理利用排序这个性质, 一步一步得到高效的算法. 经过总结, 本人觉转载 2017-03-31 18:25:40 · 322 阅读 · 0 评论 -
LeetCode 166. Fraction to Recurring Decimal
题目链接:https://leetcode.com/problems/fraction-to-recurring-decimal/题目描述:Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.If t原创 2016-08-19 22:21:23 · 417 阅读 · 0 评论 -
LeetCode 203. Remove Linked List Elements
题目链接:https://leetcode.com/problems/remove-linked-list-elements/题目描述:Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 -原创 2016-08-19 11:34:40 · 192 阅读 · 0 评论 -
Leetcode 401. Binary Watch
题目链接:https://leetcode.com/problems/binary-watch/题目描述:A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59).Each L原创 2016-10-28 22:03:25 · 340 阅读 · 0 评论 -
LeetCode 39.Combination Sum,40. Combination Sum II,216. Combination Sum III
题目链接:https://leetcode.com/problems/combination-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.原创 2016-09-05 21:05:14 · 276 阅读 · 0 评论 -
leetcode 349. Intersection of Two Arrays, 350. Intersection of Two Arrays II
题目链接:https://leetcode.com/problems/intersection-of-two-arrays/题目描述:Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2],原创 2016-08-18 20:20:55 · 262 阅读 · 0 评论 -
LeetCode 121. Best Time to Buy and Sell Stock(dynamic programming)
题目链接:https://leetcode.com/problems/best-time-to-buy-and-sell-stock/题目描述:Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to原创 2016-09-06 21:34:40 · 168 阅读 · 0 评论 -
LeetCode 122. Best Time to Buy and Sell Stock II(greedy)
题目链接:https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/题目描述:Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to fin原创 2016-09-06 21:26:12 · 320 阅读 · 0 评论 -
LeetCode 205. Isomorphic Strings
题目链接:https://leetcode.com/problems/isomorphic-strings/题目描述:Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to原创 2016-08-25 11:13:24 · 230 阅读 · 0 评论 -
LeetCode 127. Word Ladder
题目链接:https://leetcode.com/problems/word-ladder/题目描述:Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence frombeginWord to原创 2016-09-13 14:51:51 · 236 阅读 · 0 评论 -
LeetCode 21. Merge Two Sorted Lists
题目链接:https://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 together the nodes of the firs原创 2016-08-22 21:39:17 · 209 阅读 · 0 评论 -
LeetCode 242. Valid Anagram
题目链接:https://leetcode.com/problems/valid-anagram/题目描述:Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return tr原创 2016-09-12 17:22:53 · 149 阅读 · 0 评论 -
LeetCode 143.Reordered List
题目链接:https://leetcode.com/submissions/detail/71139999/题目描述:Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' val原创 2016-08-21 22:01:58 · 237 阅读 · 0 评论 -
LeetCode 374. Guess Number Higher or Lower
题目链接:https://leetcode.com/problems/guess-number-higher-or-lower/题目描述:We are playing the Guess Game. The game is as follows:I pick a number from 1 to n. You have to guess which number I原创 2016-08-31 19:01:08 · 292 阅读 · 0 评论 -
Leetcode 38. Count and Say
题目链接:https://leetcode.com/problems/count-and-say/题目描述: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" o原创 2016-09-11 16:09:28 · 170 阅读 · 0 评论 -
LeetCode 34. Search for a Range(binary search)
题目链接:https://leetcode.com/problems/search-for-a-range/题目描述:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexi原创 2016-09-07 21:57:57 · 153 阅读 · 0 评论 -
LeetCode 16. 3Sum Closest LeetCode 18. 4Sum
题目链接:https://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 the sum of the thre原创 2016-08-23 21:12:03 · 254 阅读 · 0 评论 -
LeetCode 394. Decode String LeetCode 385. Mini Parser
题目链接:https://leetcode.com/problems/decode-string/题目描述:The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note tha原创 2016-09-16 21:07:08 · 345 阅读 · 0 评论 -
78. Subsets,90. Subsets II
题目链接:https://leetcode.com/problems/subsets-ii/题目描述:Given a collection of integers that might contain duplicates, nums, return all possible subsets.Note: The solution set must not contain d原创 2016-11-07 21:38:17 · 197 阅读 · 0 评论