![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
文章平均质量分 56
jan_deng
这个作者很懒,什么都没留下…
展开
-
LeetCode OJ 105. Construct Binary Tree from Preorder and Inorder Traversal
LeetCode OJ 105. Construct Binary Tree from Preorder and Inorder TraversalDescriptionGiven preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not原创 2017-02-28 11:40:10 · 235 阅读 · 0 评论 -
LeetCode OJ 496. Next Greater Element I
LeetCode OJ 513. Find Bottom Left Tree ValueDescriptionYou are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nu原创 2017-03-23 20:03:00 · 234 阅读 · 0 评论 -
LeetCode OJ 50. Pow(x, n)
LeetCode OJ 50. Pow(x, n)DescriptionImplement pow(x, n).解题思路最简单的思路是循环n次,做n次乘法,这样的复杂度是O(n)。但是有一种更好的做法:根据对称性,我们可以把前后n/2个x的乘积看成一个整体,如果n为奇数,则这两部分相乘后只要再乘一次x就是最终结果;否则直接为所求结果。这样一直递归下去,每一次缩小的是当前x集合的1/2。所以时间复杂度原创 2017-03-14 17:40:22 · 202 阅读 · 0 评论 -
LeetCode OJ 503. Next Greater Element II
LeetCode OJ 503. Next Greater Element IIDescriptionGiven a circular array (the next element of the last element is the first element of the array), print the Next Greater Number for every element. The原创 2017-03-24 13:02:26 · 208 阅读 · 0 评论 -
LeetCode OJ 155. Min Stack
LeetCode OJ 155. Min StackDescriptionDesign a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) – Push element x onto stack.pop() – Removes the element o原创 2017-04-02 15:41:39 · 270 阅读 · 0 评论 -
LeetCode OJ 399. Evaluate Division
LeetCode OJ 399. Evaluate DivisionDescriptionEquations 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原创 2017-04-23 22:33:35 · 242 阅读 · 0 评论 -
LeetCode OJ 62. Unique Paths
LeetCode OJ 62. Unique PathsDescriptionA 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 in time.原创 2017-04-25 10:26:23 · 207 阅读 · 0 评论 -
LeetCode OJ 566. Reshape the Matrix
LeetCode OJ 566. Reshape the MatrixDescriptionIn MATLAB, there is a very useful function called ‘reshape’, which can reshape a matrix into a new one with different size but keep its original data.You’r原创 2017-05-27 16:05:07 · 247 阅读 · 0 评论 -
LeetCode OJ 12. Integer to Roman
LeetCode OJ 513. Find Bottom Left Tree ValueDescriptionGiven an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.解题思路整数转换为罗马数字,用一个二维数组保存1-9,10-90,100-900原创 2017-05-27 16:30:36 · 346 阅读 · 0 评论 -
LeetCode OJ 13. Roman to Integer
LeetCode OJ 13. Roman to IntegerDescriptionGiven a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.解题思路罗马数字转换为整数:我们把1,10,100,1000,5,500,500和对应的罗马数字做映射。原创 2017-05-27 16:42:44 · 276 阅读 · 0 评论 -
LeetCode OJ 239. Sliding Window Maximum
LeetCode OJ 239. Sliding Window MaximumDescriptionGiven an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numb原创 2017-04-08 21:19:34 · 214 阅读 · 0 评论 -
LeetCode OJ 141. Linked List Cycle
LeetCode OJ 141. Linked List CycleDescriptionGiven a linked list, determine if it has a cycle in it.Follow up: Can you solve it without using extra space?解题思路对于判断环的问题,可以采用双指针(快慢指针)的方法来判断。另外,因为题目中给的Lis原创 2017-03-21 20:30:41 · 235 阅读 · 0 评论 -
LeetCode OJ 160. Intersection of Two Linked Lists
LeetCode OJ 160. Intersection of Two Linked ListsDescriptionWrite a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A:原创 2017-03-21 19:48:18 · 201 阅读 · 0 评论 -
LeetCode OJ 106. Construct Binary Tree from Inorder and Postorder Traversal
LeetCode OJ 106. Construct Binary Tree from Inorder and Postorder TraversalDescriptionGiven inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do n原创 2017-02-28 14:24:30 · 411 阅读 · 0 评论 -
LeetCode OJ 442. Find All Duplicates in an Array
LeetCode OJ 442. Find All Duplicates in an ArrayDescriptionGiven an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements that app原创 2017-02-28 21:48:31 · 204 阅读 · 0 评论 -
LeetCode OJ 405. Convert a Number to Hexadecimal
LeetCode OJ 405. Convert a Number to HexadecimalDescriptionGiven an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used.Note:All letters in原创 2017-02-24 16:50:16 · 221 阅读 · 0 评论 -
LeetCode OJ 451. Sort Characters By Frequency
LeetCode OJ 451. Sort Characters By FrequencyDescriptionGiven a string, sort it in decreasing order based on the frequency of characters.Example1 Input: “tree” Output: “eert” Explanat原创 2017-02-24 20:58:47 · 413 阅读 · 0 评论 -
LeetCode OJ 515. Find Largest Value in Each Tree Row
LeetCode OJ 515. Find Largest Value in Each Tree RowDescriptionYou need to find the largest value in each row of a binary tree.Example Input: 1 / \ 3 2 / \ \ 5 3 9 O原创 2017-02-25 14:33:33 · 322 阅读 · 0 评论 -
LeetCode OJ 240. Search a 2D Matrix II
LeetCode OJ 240. Search a 2D Matrix IIDescriptionWrite an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted in原创 2017-03-06 09:56:59 · 255 阅读 · 0 评论 -
LeetCode OJ 226. Invert Binary Tree
LeetCode OJ 226. Invert Binary TreeDescriptionInvert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1方法一Recursion: 递归,每一次翻转左右子树。这种方法要每次原创 2017-03-20 17:35:55 · 210 阅读 · 0 评论 -
LeetCode OJ 56. Merge Intervals
LeetCode OJ 56. Merge IntervalsDescriptionGiven a collection of intervals, merge all overlapping intervals.For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18].解题思路这道题的题意是将重叠的区间原创 2017-03-07 15:43:26 · 204 阅读 · 0 评论 -
LeetCode OJ 406. Queue Reconstruction by Height
LeetCode OJ 406. Queue Reconstruction by HeightDescriptionSuppose 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 t原创 2017-03-07 16:35:52 · 215 阅读 · 0 评论 -
LeetCode OJ 207. Course Schedule
LeetCode OJ 207. Course Schedule典型的拓扑排序算法。谨以此题纪念期末机考时没AC这么简单的拓扑排序。upset……ingDescriptionThere are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for原创 2017-02-28 20:32:16 · 238 阅读 · 0 评论