Array
文章平均质量分 70
dyllanzhou
这个作者很懒,什么都没留下…
展开
-
[Leetcode]Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue. Here, we will use the integers 0,原创 2015-09-25 15:03:33 · 279 阅读 · 0 评论 -
[Leetcode]Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. For example, Given nums = [0, 1, 3] return 2. Note: Your algorithm should run原创 2015-09-23 16:57:31 · 300 阅读 · 0 评论 -
[Leetcode]Combination Sum
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 unlimited numbe原创 2015-10-12 21:37:19 · 276 阅读 · 0 评论 -
[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 · 347 阅读 · 0 评论 -
[Leetcode]Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates in the array.原创 2015-09-22 14:18:00 · 242 阅读 · 0 评论 -
[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 · 254 阅读 · 0 评论 -
[Leetcode]Best Time to Buy and Sell Stock
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 of the stock), des原创 2015-09-24 16:18:55 · 246 阅读 · 0 评论 -
[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 · 254 阅读 · 0 评论 -
[Leetcode]Unique Paths
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the bo原创 2015-09-24 16:49:47 · 236 阅读 · 0 评论 -
[Leetcode]Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Note: You can only move either down or right at原创 2015-09-25 17:21:19 · 234 阅读 · 0 评论 -
[Leetcode]Spiral Matrix
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For example, Given the following matrix: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] You原创 2015-11-13 22:29:44 · 188 阅读 · 0 评论 -
[Leetcode]Word Search
Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically n原创 2015-11-13 21:30:03 · 176 阅读 · 0 评论 -
[Leetcode]Longest Consecutive Sequence
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example, Given [100, 4, 200, 1, 3, 2], The longest consecutive elements sequence is [1, 2, 3,原创 2015-12-17 20:06:59 · 437 阅读 · 0 评论 -
[Leetcode]Find the Duplicate Number
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, f原创 2015-12-01 15:37:38 · 259 阅读 · 0 评论 -
[cc150]Chapter 3 | Stacks and Queues
Describe how you could use a single array to implement three stacks. 1)solution 1 divide the array to 3 part, so each part can be one stack, but for each stack is limited to n/3 size [stk1][stk原创 2015-12-04 14:42:51 · 306 阅读 · 0 评论 -
[Leetcode]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. * struct Inter原创 2016-01-29 15:31:12 · 317 阅读 · 0 评论 -
[Leetcode]Find Minimum 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). Find the minimum element. You may assume no duplicate exists in the arra原创 2015-09-23 16:36:50 · 289 阅读 · 0 评论 -
[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 · 358 阅读 · 0 评论 -
[Leetcode]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-09-22 15:40:47 · 255 阅读 · 0 评论 -
[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 · 247 阅读 · 0 评论 -
[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 · 223 阅读 · 0 评论 -
[Leetcode]Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 to n2 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 · 286 阅读 · 0 评论 -
[Leetcode]Combination Sum II
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 in the combinatio原创 2015-11-04 15:45:14 · 214 阅读 · 0 评论 -
[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 line i is at (i, ai) and (i, 0). Find原创 2015-10-04 23:27:32 · 253 阅读 · 0 评论 -
[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 · 278 阅读 · 0 评论 -
[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 · 205 阅读 · 0 评论 -
[Leetcode]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-11-05 14:27:40 · 221 阅读 · 0 评论 -
[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 · 214 阅读 · 0 评论 -
[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 · 229 阅读 · 0 评论 -
[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 · 282 阅读 · 0 评论 -
[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 · 277 阅读 · 0 评论 -
[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 · 426 阅读 · 0 评论 -
[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 · 355 阅读 · 0 评论 -
[Leetcode]Combination Sum III
Find all possible combinations of k numbers that add up to a number n, 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 · 291 阅读 · 0 评论 -
[Leetcode]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. Examp原创 2016-01-29 16:14:55 · 336 阅读 · 0 评论