CodeReview
文章平均质量分 74
amberFeb
这个作者很懒,什么都没留下…
展开
-
第78题 Binary Tree Level Order Traversal
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 / \ 9 20 /原创 2015-05-15 21:40:05 · 338 阅读 · 0 评论 -
第60题 Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Hide Tags Divide and Conquer Linked List HeapCode原创 2015-05-09 18:08:26 · 349 阅读 · 0 评论 -
第65题 Container With Most Water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin原创 2015-05-10 00:22:19 · 249 阅读 · 0 评论 -
第64题 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 three integers. You may assume that each input would have exact原创 2015-05-09 23:30:25 · 394 阅读 · 0 评论 -
第63题 3Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,c)原创 2015-05-09 22:14:03 · 312 阅读 · 0 评论 -
第55题 Unique Binary Search Trees II
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown below. 1 3原创 2015-05-02 18:46:04 · 406 阅读 · 0 评论 -
第56题 Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the followi原创 2015-05-02 21:37:34 · 313 阅读 · 0 评论 -
第59题 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 first two lists.Hide Tags Linked List原创 2015-05-09 17:31:50 · 268 阅读 · 0 评论 -
第六题 Unique Binary Search Trees
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 1 \原创 2014-10-06 05:55:37 · 317 阅读 · 0 评论 -
第54题 Validate Binary Search Tree
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.The原创 2015-05-02 17:13:48 · 290 阅读 · 0 评论 -
第51题 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-04-04 17:23:02 · 476 阅读 · 0 评论 -
第49题 Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit st原创 2015-03-18 01:29:34 · 261 阅读 · 0 评论 -
第50题 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.Hide Tags String原创 2015-03-18 03:08:35 · 370 阅读 · 0 评论 -
第48题 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", retur原创 2015-03-17 16:44:08 · 348 阅读 · 0 评论 -
第28题 Valid Number
Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueNote: It is intended for the problem statement to be ambiguo原创 2015-01-04 15:36:27 · 374 阅读 · 0 评论 -
第29题 Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all vali原创 2015-01-04 17:47:38 · 364 阅读 · 0 评论 -
第27题 ZigZag Conversion
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 NA P L S I原创 2015-01-03 17:35:59 · 292 阅读 · 0 评论 -
第44题 Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()()"原创 2015-01-20 18:28:23 · 344 阅读 · 0 评论 -
第61题 Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. You m原创 2015-05-09 18:18:13 · 370 阅读 · 0 评论 -
第62题 Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, where原创 2015-05-09 18:53:20 · 263 阅读 · 0 评论 -
第53题 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.Hide Tags Math String原创 2015-04-29 00:23:12 · 313 阅读 · 0 评论 -
第77题 Maximum Product Subarray
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] has the largest pr原创 2015-05-11 18:49:27 · 307 阅读 · 0 评论 -
第76题 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-05-11 18:20:53 · 354 阅读 · 0 评论 -
第75题 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 get t.All occurrences of a character must be replaced with another原创 2015-05-11 17:53:45 · 289 阅读 · 0 评论 -
第74题 Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x.Hide Tags Math Binary SearchCode in C++:class Solution {public:原创 2015-05-11 17:29:30 · 407 阅读 · 0 评论 -
第73题 Largest Number
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-05-11 16:34:22 · 327 阅读 · 0 评论 -
第52题 Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum window is "BANC".原创 2015-04-28 02:29:39 · 378 阅读 · 0 评论 -
第57题 Sum Root to Leaf Numbers
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.Find the total原创 2015-05-03 00:11:34 · 309 阅读 · 0 评论 -
第72题 Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.Hide Tags Tree Array Depth-first Search原创 2015-05-11 03:14:35 · 349 阅读 · 0 评论 -
第70题 Populating Next Right Pointers in Each Node
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If t原创 2015-05-11 01:45:41 · 293 阅读 · 0 评论 -
第69题 Divide Two Integers
Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.Hide Tags Math Binary Search原创 2015-05-11 01:02:24 · 281 阅读 · 0 评论 -
第71题 Balanced Binary Tree
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 never differ原创 2015-05-11 02:05:06 · 336 阅读 · 0 评论 -
第68题 Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using原创 2015-05-10 02:26:38 · 250 阅读 · 0 评论 -
第67题 Subsets
Given a set of distinct integers, nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For exampl原创 2015-05-10 01:18:26 · 339 阅读 · 0 评论 -
第58题 Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−1,2,1] has原创 2015-05-09 01:35:10 · 273 阅读 · 0 评论 -
第66题 4Sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:Elements原创 2015-05-10 00:45:57 · 377 阅读 · 0 评论 -
第36题 Compare Version Numbers
Compare two version numbers version1 and version1.If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and cont原创 2015-01-13 18:19:37 · 411 阅读 · 0 评论 -
第43题 Edit Distance
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:原创 2015-01-20 17:47:29 · 271 阅读 · 0 评论 -
第42题 Distinct Subsequences
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 some (can be none)原创 2015-01-19 17:27:19 · 394 阅读 · 0 评论 -
第39题 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" or 11.11 is read off as "two 1s" or 21.21 is read off as "o原创 2015-01-17 15:24:21 · 259 阅读 · 0 评论