- 博客(41)
- 收藏
- 关注
原创 [Leetcode]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].
2015-10-28 00:12:08 395
原创 [Leetcode]Gas Station
There are N gas stations along a circular route, where the amount of gas at stationi is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from stationi to it
2015-10-27 23:55:14 274
原创 [Leetcode]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 string
2015-10-27 21:34:48 325
原创 [Leetcode]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 follo
2015-10-27 21:09:10 625
原创 [Leetcode]Graph Valid Tree
Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), write a function to check whether these edges make up a valid tree.For example:Given n =
2015-10-27 16:41:59 850
原创 [Leetcode]Binary Tree Zigzag Level Order Traversal
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:Given binary tr
2015-10-27 00:03:15 317
原创 [Leetcode]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./** * Definition for a binary tree node. * struct Tre
2015-10-26 23:47:17 244
原创 [Leetcode]Path Sum II
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 / \
2015-10-26 23:17:23 232
原创 [Leetcode]Pow(x, n)
Implement pow(x, n).Have you met this question in a real interview?class Solution {public: /*algorithm: divde and conqure */ double myPow(double x,
2015-10-26 20:31:41 275
原创 [Leetcode]Jump Game
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.Determine if
2015-10-26 19:54:14 343
原创 [Leetcode]3Sum Smaller
Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 that satisfy the condition nums[i] + nums[j] + nums[k] .For example, given nums = [-2, 0, 1, 3
2015-10-25 22:59:38 412
原创 [Leetcode]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 exactly
2015-10-25 22:54:36 344
原创 [Leetcode]Palindrome Partitioning II
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 = "aab",Return 1 s
2015-10-25 18:13:55 265
原创 [Leetcode]Palindrome Partitioning
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 [ ["aa","b"],
2015-10-24 15:03:39 248
原创 [Leetcode]Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree./** * Definition for a binary tree node. * struct Tr
2015-10-24 14:44:54 272
原创 [Leetcode]Insertion Sort List
Sort a linked list using insertion sort./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */
2015-10-23 13:47:20 234
原创 [Leetcode]Partition List
Given a linked list and a value x, partition it such that all nodes less thanx come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of
2015-10-23 12:51:10 255
原创 [Leetcode]Triangle
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], [3,4], [6,
2015-10-22 20:37:54 220
原创 [Leetcode]Unique Paths II
Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in the grid.
2015-10-22 19:33:27 205
原创 [Leetcode]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 1I
2015-10-22 18:53:10 225
原创 [Leetcode] 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-10-16 12:24:57 211
原创 [Leetcode]Subsets II
Given a collection of integers that might contain duplicates, nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain dupl
2015-10-13 20:10:03 243
原创 [Leetcode]Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for singly-linked list. * struct ListNode { * int val; * Lis
2015-10-12 22:03:00 268
原创 [Leetcode]Combination Sum
Given a set of candidate numbers (C) and a target number (T), find all unique combinations inC where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited numbe
2015-10-12 21:37:19 257
原创 [Leetcode]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 example,
2015-10-12 15:48:51 338
原创 [Leetcode]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 \
2015-10-11 17:04:06 242
原创 [Leetcode]Binary Search Tree Iterator
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the BST.Note: next() and
2015-10-11 11:44:37 263
原创 [Leetcode]Combination Sum III
Find all possible combinations of k numbers that add up to a numbern, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Ensure that numbers wit
2015-10-11 11:37:04 280
原创 [Leetcode]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 number123.Find the total sum
2015-10-09 19:43:15 235
原创 [Leetcode]Peeking Iterator
Given an Iterator class interface with methods: next() and hasNext(), design and implement a PeekingIterator that support the peek() operation -- it essentially peek() at the element that will be re
2015-10-09 19:17:01 347
原创 [Leetcode]Combinations
Given two integers n and k, return all possible combinations ofk numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]
2015-10-08 18:06:27 277
原创 [Leetcode]Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Note: Do not modify the linked list.Follow up:Can you solve it without using extra space?/**
2015-10-08 15:00:09 195
原创 [Leetcode]Word Pattern
Given a pattern and a string str, find if str follows the same pattern.Examples:pattern = "abba", str = "dog cat cat dog" should return true.pattern = "abba", str = "dog cat cat fish" should r
2015-10-06 19:15:06 280
原创 [Leetcode]Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.click to show follow up.Follow up:Did you use extra space?A straight forward solution using O(mn) s
2015-10-05 22:36:18 196
原创 [Leetcode]Search a 2D Matrix
Write 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 from left to right.The first integer of each
2015-10-05 17:25:23 266
原创 [Leetcode]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 linei is at (i, ai) and (i, 0). Find
2015-10-04 23:27:32 246
原创 [Leetcode]Find Peak Element
A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple peaks, in that
2015-10-01 22:04:38 237
原创 [Leetcode]Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 ton2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [
2015-10-01 21:31:23 272
原创 [Leetcode]Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?class Solution {public: /*alogirthm: x(i,j)-->x'
2015-10-01 17:17:01 212
原创 [Leetcode]Permutations
Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1],[3,1,2], and [3,2,1].class Solution
2015-10-01 16:22:40 213
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人