
leetcode
文章平均质量分 70
风陵渡口
hi
展开
-
Trapping Rain Water
Problem:Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,原创 2014-10-10 21:32:06 · 429 阅读 · 0 评论 -
Palindrome Partitioning
Problem:Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return原创 2014-10-02 23:46:39 · 324 阅读 · 0 评论 -
Palindrome Partitioning II
Problem:Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s =原创 2014-10-02 23:47:46 · 311 阅读 · 0 评论 -
Sum Root to Leaf Numbers
Problem:Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.原创 2014-10-02 23:50:15 · 347 阅读 · 0 评论 -
Binary Tree Maximum Path Sum
Problem: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 3原创 2014-10-02 23:55:06 · 385 阅读 · 0 评论 -
Combination Sum
Problem: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.The same repeated number may be chosen from C原创 2014-10-13 22:32:50 · 529 阅读 · 1 评论 -
First Missing Positive
Problem:Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and原创 2014-10-11 09:12:26 · 374 阅读 · 0 评论 -
Word Ladder II
Problem: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原创 2014-10-03 12:35:47 · 437 阅读 · 0 评论 -
Binary Tree Level Order Traversal II
Problem: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,原创 2014-10-03 12:49:42 · 366 阅读 · 0 评论 -
Clone Graph
Problem:Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a se原创 2014-10-02 23:45:43 · 376 阅读 · 0 评论 -
Gas Station
Problem:There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to trave原创 2014-10-02 23:44:52 · 353 阅读 · 0 评论 -
Scramble String
Problem: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原创 2014-10-02 23:41:49 · 478 阅读 · 0 评论 -
Candy
Problem:There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must ha原创 2014-10-02 23:33:50 · 616 阅读 · 0 评论 -
Search in Rotated Sorted Array II
Problem:Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given ta原创 2014-10-02 23:34:45 · 320 阅读 · 0 评论 -
Remove Duplicates from Sorted List
Problem:Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.Solutio原创 2014-10-02 23:36:36 · 271 阅读 · 0 评论 -
Remove Duplicates from Sorted List II
Problem:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5原创 2014-10-02 23:37:42 · 377 阅读 · 0 评论 -
Largest Rectangle in Histogram
Problem: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 w原创 2014-10-02 23:38:36 · 318 阅读 · 0 评论 -
Maximum Product Subarray
Problem:Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],the contiguous subarray [2,3] ha原创 2014-10-02 23:37:52 · 396 阅读 · 0 评论 -
Maximal Rectangle
Problem:Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.数组heits记录同一行中'1'的高度。如果'1'增长,就把行号压栈,因为面积在增大;如果'1'缩短,就把行号退栈,在面积原创 2014-10-02 23:40:10 · 316 阅读 · 0 评论 -
Partition List
Problem:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the no原创 2014-10-02 23:40:57 · 280 阅读 · 0 评论 -
Best Time to Buy and Sell Stock II
Problem: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 li原创 2014-10-03 12:33:39 · 300 阅读 · 0 评论 -
Best Time to Buy and Sell Stock III
Problem: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 at most two transactions.N原创 2014-10-03 12:37:27 · 311 阅读 · 0 评论 -
Triangle
Problem: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],原创 2014-10-03 12:38:50 · 306 阅读 · 0 评论 -
Binary Tree Zigzag Level Order Traversal
Problem:Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:原创 2014-10-03 12:51:15 · 320 阅读 · 0 评论 -
Best Time to Buy and Sell Stock
Problem: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 complete at most one transaction (ie, buy one and sell one share原创 2014-10-03 12:27:07 · 252 阅读 · 0 评论 -
Pascal's Triangle II
Problem:Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?原创 2014-10-03 12:40:43 · 286 阅读 · 0 评论 -
Populating Next Right Pointers in Each Node II
Problem:Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only原创 2014-10-03 12:43:19 · 357 阅读 · 0 评论 -
Convert Sorted Array to Binary Search Tree
Problem:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.先序遍历。Solution:/** * Definition for binary tree * public class TreeNod原创 2014-10-03 12:50:44 · 322 阅读 · 0 评论 -
Count and Say
Problem: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" or 11.11 is read off as "two 1s" or 21.21 i原创 2014-10-14 11:13:09 · 423 阅读 · 0 评论 -
Search for a Range
Problem:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target原创 2014-10-15 15:54:59 · 400 阅读 · 0 评论 -
Sudoku Solver
Problem:Write 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.原创 2014-10-15 10:05:37 · 483 阅读 · 0 评论 -
Distinct Subsequences
Problem:Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting so原创 2014-10-03 12:44:30 · 308 阅读 · 0 评论 -
Combination Sum II
Problem:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once原创 2014-10-14 10:31:26 · 437 阅读 · 0 评论 -
Binary Tree Level Order Traversal
Problem: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,#,#,15,7}, 3 / \原创 2014-10-03 12:53:23 · 295 阅读 · 0 评论 -
Pascal's Triangle
Problem:Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]杨辉三角。Sol原创 2014-10-03 12:38:11 · 314 阅读 · 0 评论 -
Populating Next Right Pointers in Each Node
Problem:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its n原创 2014-10-03 12:41:32 · 600 阅读 · 0 评论 -
Flatten Binary Tree to Linked List
Problem: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原创 2014-10-03 12:45:58 · 334 阅读 · 0 评论 -
Path Sum II
Problem:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5原创 2014-10-03 12:45:19 · 299 阅读 · 0 评论 -
Minimum Depth of Binary Tree
Problem: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.Solution:/** *原创 2014-10-03 12:46:24 · 315 阅读 · 0 评论 -
Balanced Binary Tree
Problem: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 no原创 2014-10-03 12:48:37 · 350 阅读 · 0 评论