Review
文章平均质量分 77
cgdong2014
这个作者很懒,什么都没留下…
展开
-
Largest Rectangle in Histogram
Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width of ea原创 2014-10-16 13:03:59 · 252 阅读 · 0 评论 -
Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1原创 2014-09-28 11:34:21 · 228 阅读 · 0 评论 -
Jump Game II
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.Your goal i原创 2014-12-13 04:19:25 · 211 阅读 · 0 评论 -
Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible o转载 2015-01-24 09:58:34 · 229 阅读 · 0 评论 -
Search in Rotated Sorted Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array return it原创 2014-10-19 12:42:38 · 211 阅读 · 0 评论 -
Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB Credits:S原创 2015-01-06 02:51:45 · 228 阅读 · 0 评论 -
Find Next Node in InOrder Traverse
在一个二叉树的 Inorder 遍历中, 找到该节点的 下一个节点原创 2014-10-14 12:13:29 · 394 阅读 · 0 评论 -
Remove Duplicates from Sorted Array II
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array A = [1,1,1,2,2,3],Your function should return length = 5, and A is now [1,1,2,2,原创 2015-01-23 12:23:54 · 252 阅读 · 0 评论 -
Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB 思路:从低原创 2014-12-22 06:43:21 · 294 阅读 · 0 评论 -
LRU Cache
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the key if原创 2014-09-19 09:43:22 · 259 阅读 · 0 评论 -
Maximum Gap
Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 if the array contains less than 2 elements原创 2015-02-23 06:09:36 · 395 阅读 · 0 评论 -
Merge Intervals
Given 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].Show TagsHave you met this quest原创 2015-01-24 12:40:13 · 203 阅读 · 0 评论 -
Majority Element
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 majority element原创 2015-03-02 07:17:55 · 233 阅读 · 0 评论 -
Sudoku Solver
rite a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.A sudoku原创 2015-03-10 09:38:06 · 245 阅读 · 0 评论 -
Longest Increasing Subsequence
Given a sequence of integers, find the longest increasing subsequence (LIS).You code should return the length of the LIS.Have you met this question in a real interview? YesExampl原创 2015-08-17 12:04:16 · 297 阅读 · 0 评论 -
Rectangle Area
Find 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 ar原创 2015-07-25 04:02:37 · 203 阅读 · 0 评论 -
Kth Largest Element in an Array
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,Given [3,2,1,5,6,4] and k = 2, return 5.N原创 2015-07-24 04:35:51 · 200 阅读 · 0 评论 -
KMP
与传统的字符串匹配(BF算法)相比,ji原创 2014-10-16 13:48:30 · 200 阅读 · 0 评论 -
Word Search II
Given a 2D board and a list of words from the dictionary, find all words in the board.Each word must be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horiz原创 2015-08-03 23:57:38 · 218 阅读 · 0 评论 -
Different Ways to Add Parentheses
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 *.Example 1Inp原创 2015-08-03 11:45:32 · 233 阅读 · 0 评论 -
Shortest Palindrome
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation.For exampl原创 2015-08-16 04:48:49 · 367 阅读 · 0 评论 -
Word Break
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "leetcode",dict = ["leet"原创 2014-09-22 02:41:11 · 212 阅读 · 0 评论 -
Count Complete Tree Nodes
Given a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely filled, a原创 2015-08-10 10:58:21 · 274 阅读 · 0 评论 -
Multiply Strings
Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.这道题属于数值操作的题目,其实更多地是考察乘法运算的本质。基本思路是和转载 2015-01-03 08:05:15 · 347 阅读 · 0 评论 -
Maximal Rectangle
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.思路: First, we storage the width of every原创 2014-10-16 08:25:41 · 223 阅读 · 0 评论 -
Permutation Sequence
The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):"123""132""213""231""312原创 2015-01-01 09:12:51 · 222 阅读 · 0 评论 -
Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n satisfy the fol原创 2014-10-14 11:47:13 · 242 阅读 · 0 评论 -
Find Minimum in Rotated Sorted Array I & II
Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).Find the minimum element.You may assume no duplicate exists in the ar原创 2015-01-10 14:34:09 · 223 阅读 · 0 评论 -
Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()", wh原创 2015-01-08 13:27:25 · 195 阅读 · 0 评论 -
Interleaving String
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", r原创 2014-12-22 09:01:14 · 187 阅读 · 0 评论 -
Max Points on a Line
思路: Need to consider the same points and vertical points.原创 2014-09-19 07:31:13 · 215 阅读 · 0 评论 -
Binary Tree Maximum Path Sum
Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3Return 6.原创 2014-09-24 11:21:28 · 206 阅读 · 0 评论 -
Integer to Roman
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.罗马数字有如下符号:基本字符IVXLCDM对应阿拉伯数字151050100500原创 2015-01-10 11:20:17 · 240 阅读 · 0 评论 -
Scramble String
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great": great / \ gr原创 2015-01-01 13:57:17 · 302 阅读 · 0 评论 -
Word Ladder II
Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to end, such that:Only one letter can be changed at a timeEach intermediate word must exi原创 2014-12-30 09:46:11 · 305 阅读 · 0 评论 -
Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.思路: Traverse the s原创 2014-12-22 07:35:20 · 210 阅读 · 0 评论 -
Min Stack
Design 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 on top of the stack.top() -- Get转载 2015-01-08 04:30:15 · 247 阅读 · 0 评论 -
Largest Number @leetCode
Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result may be very原创 2015-01-13 04:36:24 · 244 阅读 · 0 评论 -
Subsets II
Given a collection of integers that might contain duplicates, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplica原创 2014-10-15 08:24:04 · 277 阅读 · 0 评论 -
Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and [2,1,1].原创 2014-12-31 09:05:18 · 236 阅读 · 0 评论