
leetcode
文章平均质量分 73
xudli
这个作者很懒,什么都没留下…
展开
-
leetcode 49: Swap Nodes in Pairs
Feb 15 '12Given 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原创 2013-01-23 16:03:52 · 571 阅读 · 0 评论 -
leetcode 108: Combination Sum II
Combination Sum IIMar 7 '12Given 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原创 2013-03-09 16:04:01 · 803 阅读 · 0 评论 -
leetcode4: 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.key-point原创 2012-12-20 15:38:41 · 768 阅读 · 0 评论 -
leetcode 106: Binary Tree Zigzag Level Order Traversal
Binary Tree Zigzag Level Order TraversalSep 29 '12Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the nex原创 2013-03-09 11:56:22 · 732 阅读 · 0 评论 -
leetcode 107: Climbing Stairs
Climbing StairsApr 3 '12You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?原创 2013-03-09 12:34:13 · 939 阅读 · 0 评论 -
leetcode12: First Missing Positive
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 uses constant s原创 2012-12-22 13:42:55 · 595 阅读 · 0 评论 -
leetcode 111: Distinct Subsequences
Distinct SubsequencesOct 19 '12Given 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 ori原创 2013-03-11 06:15:30 · 1049 阅读 · 0 评论 -
leetcode 112: Gray Code
Gray CodeMay 20 '12The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the c原创 2013-03-12 08:00:01 · 1823 阅读 · 1 评论 -
leetcode 21: Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is原创 2013-01-09 06:04:27 · 1172 阅读 · 0 评论 -
leetcode 113: Jump Game
Jump GameMar 25 '12Given 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原创 2013-03-12 16:41:01 · 1159 阅读 · 0 评论 -
leetcode 114: Jump Game II
Jump Game IIMar 17 '12Given 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原创 2013-03-12 16:53:24 · 864 阅读 · 0 评论 -
leetcode 28: 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]./** * Definition for an interval. * st原创 2013-01-11 07:05:24 · 2217 阅读 · 0 评论 -
leetcode 115: Longest Valid Parentheses
Longest Valid ParenthesesMar 1 '12Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the lon原创 2013-03-13 07:56:11 · 1201 阅读 · 0 评论 -
leetcode 117: Palindrome Number
Palindrome NumberJan 4 '12Determine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinki原创 2013-03-13 18:03:09 · 1138 阅读 · 1 评论 -
leetcode 29: Merge Sorted Array
Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space to hold additional elements from B. The number of elements initialized in A原创 2013-01-11 07:28:42 · 3355 阅读 · 2 评论 -
leetcode 30: 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./** * Definition for singly-linked list. * struct原创 2013-01-11 07:55:20 · 645 阅读 · 0 评论 -
leetcode 116: Multiply Strings (uncompleted)
Multiply StringsMar 12 '12Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.原创 2013-03-13 17:49:40 · 890 阅读 · 0 评论 -
leetcode 53: Sqrt(x)
Sqrt(x)Apr 3 '12Implement int sqrt(int x).Compute and return the square root of x.class Solution {public: int sqrt(int x) { // Start typing your C/C++ solution b原创 2013-01-26 05:25:01 · 1552 阅读 · 0 评论 -
leetcode 38: Remove Duplicates from Sorted List II
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.Given 1->1->1原创 2013-01-16 08:21:51 · 1141 阅读 · 1 评论 -
leetcode 36: 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,3]原创 2013-01-15 07:27:01 · 624 阅读 · 0 评论 -
leetcode 55: Valid Palindrome
Valid PalindromeJan 13Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a pal原创 2013-01-26 20:16:31 · 2970 阅读 · 0 评论 -
leetcode 16: Best Time to Buy and Sell Stock III
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.Note:You ma原创 2012-12-27 00:54:43 · 941 阅读 · 0 评论 -
leetcode 88: Next Permutation
Next PermutationImplement 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 lo原创 2013-02-23 17:52:51 · 1758 阅读 · 0 评论 -
leetcode8: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 a原创 2012-12-21 17:55:54 · 3543 阅读 · 0 评论 -
leetcode2:inorder tranversal
inorder traversalclass Solution {public: vector inorderTraversal(TreeNode *root) { // Start typing your C/C++ solution below // DO NOT write int main() function vector原创 2012-12-18 06:18:09 · 990 阅读 · 0 评论 -
leetcode 120: 3Sum
3SumJan 18 '12Given 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:原创 2013-03-19 06:38:45 · 975 阅读 · 0 评论 -
leetcode 125: Restore IP Addresses (uncompleted)
Restore IP AddressesAug 8 '12Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.25原创 2013-04-01 13:09:21 · 882 阅读 · 0 评论 -
leetcode 43: Set Matrix Zeroes
Given am xn matrix, if an element is 0, set its entire row and column to 0. Do it in place.uncompletedclass Solution {public: void setZeroes(vector > &matrix) { // Start原创 2013-01-18 09:36:46 · 1615 阅读 · 0 评论 -
leetcode 74: Permutation Sequence
Permutation SequenceMar 28 '12The 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,原创 2013-02-14 16:02:37 · 2039 阅读 · 0 评论 -
leetcode 84: Word Ladder
Word LadderFeb 11Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at原创 2013-02-21 07:44:32 · 5168 阅读 · 2 评论 -
leetcode 121: Minimum Window Substring
Minimum Window SubstringApr 15 '12Given 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 = "ADOBECODE原创 2013-03-20 17:37:51 · 1570 阅读 · 0 评论 -
leetcode 86: Sum Root to Leaf Numbers
Sum Root to Leaf Numbers2 daysGiven 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 rep原创 2013-02-22 05:38:20 · 1954 阅读 · 0 评论 -
leetcode 91: Trapping Rain Water
Trapping Rain WaterMar 10 '12Given 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 e原创 2013-03-01 06:20:28 · 934 阅读 · 0 评论 -
leetcode 72: N-Queens
N-QueensMar 20 '12The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct sol原创 2013-02-14 07:52:14 · 848 阅读 · 0 评论 -
leetcode 127: N-Queens II
N-Queens IIMar 20 '12Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions. A good optimization example: when the req原创 2013-04-05 16:39:31 · 780 阅读 · 0 评论 -
leetcode20: Insert Interval
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.原创 2013-01-08 15:25:19 · 3591 阅读 · 0 评论 -
leetcode 123: Palindrome Partitioning II
Palindrome Partitioning IIMar 1Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning o原创 2013-03-26 08:54:01 · 1307 阅读 · 0 评论 -
leetcode 54: String to Integer (atoi)
String to Integer (atoi)Dec 27 '11Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask原创 2013-01-26 19:51:38 · 4168 阅读 · 1 评论 -
leetcode 110: Construct Binary Tree from Inorder and Postorder Traversal
Construct Binary Tree from Inorder and Postorder TraversalSep 30 '12Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not原创 2013-03-10 04:50:55 · 748 阅读 · 0 评论 -
leetcode 122: Palindrome Partitioning
Palindrome PartitioningFeb 28Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, gi原创 2013-03-24 19:07:58 · 911 阅读 · 0 评论