贪心
Jump Game
Given an array of nonnegative 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 you are able to reach the last index.
Example 1:
1  Input: [2,3,1,1,4] 
Example 2:
1  Input: [3,2,1,0,4] 
1  class Solution { 
Majority Element II
Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times.
Note: The algorithm should run in linear time and in O(1) space.
Example 1:
1  Input: [3,2,3] 
Example 2:
1  Input: [1,1,1,3,3,2,2,2] 
1  class Solution { 
Queue Reconstruction by Height
Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person and k is the number of people in front of this person who have a height greater than or equal to h. Write an algorithm to reconstruct the queue.
Note:
The number of people is less than 1,100.
Example
1  Input: 
1  class Solution { 
Minimum Number of Arrows to Burst Balloons
There are a number of spherical balloons spread in twodimensional space. For each balloon, provided input is the start and end coordinates of the horizontal diameter. Since it’s horizontal, ycoordinates don’t matter and hence the xcoordinates of start and end of the diameter suffice. Start is always smaller than end. There will be at most 104 balloons.
An arrow can be shot up exactly vertically from different points along the xaxis. A balloon with xstart and xend bursts by an arrow shot at x if xstart ≤ x ≤ xend. There is no limit to the number of arrows that can be shot. An arrow once shot keeps travelling up infinitely. The problem is to find the minimum number of arrows that must be shot to burst all balloons.
Example:
1  Input: 
1  class Solution { 
Remove K Digits
Given a nonnegative integer num represented as a string, remove k digits from the number so that the new number is the smallest possible.
Note:
 The length of num is less than 10002 and will be ≥ k.
 The given num does not contain any leading zero.
Example 1:
1  Input: num = "1432219", k = 3 
Example 2:
1  Input: num = "10200", k = 1 
Example 3:
1  Input: num = "10", k = 2 
1  class Solution { 
动态规划
矩阵链相乘
1 

Gas Station
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 travel from station i to its next station (i+1). You begin the journey with an empty tank at one of the gas stations.
Return the starting gas station’s index if you can travel around the circuit once in the clockwise direction, otherwise return 1.
Note:
 If there exists a solution, it is guaranteed to be unique.
 Both input arrays are nonempty and have the same length.
 Each element in the input arrays is a nonnegative integer.
Example 1:
1  Input: 
Example 2:
1  Input: 
1  class Solution { 
Counting Bits
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an array.
Example 1:
1  Input: 2 
Example 2:
1  Input: 5 
1  class Solution { 
House Robber II
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is the neighbor of the last one. Meanwhile, adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on the same night.
Given a list of nonnegative integers representing the amount of money of each house, determine the maximum amount of money you can rob tonight without alerting the police.
Example 1:
1  Input: [2,3,2] 
Example 2:
1  Input: [1,2,3,1] 
1  class Solution { 
Largest Divisible Subset
Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of elements in this subset satisfies:
Si % Sj = 0 or Sj % Si = 0.
If there are multiple solutions, return any subset is fine.
Example 1:
1  Input: [1,2,3] 
Example 2:
1  Input: [1,2,4,8] 
1  class Solution { 
Best Time to Buy and Sell Stock with Cooldown
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 like (ie, buy one and sell one share of the stock multiple times) with the following restrictions:
You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).
After you sell your stock, you cannot buy stock on next day. (ie, cooldown 1 day)
Example:
1  Input: [1,2,3,0,2] 
1  class Solution { 
最长公共子序列
1 

Word Break
Given a nonempty string s and a dictionary wordDict containing a list of nonempty words, determine if s can be segmented into a spaceseparated sequence of one or more dictionary words.
Note:
 The same word in the dictionary may be reused multiple times in the segmentation.
 You may assume the dictionary does not contain duplicate words.
Example 1:
1  Input: s = "leetcode", wordDict = ["leet", "code"] 
Example 2:
1  Input: s = "applepenapple", wordDict = ["apple", "pen"] 
Example 3:
1  Input: s = "catsandog", wordDict = ["cats", "dog", "sand", "and", "cat"] 
1  class Solution { 
Wiggle Subsequence
A sequence of numbers is called a wiggle sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with fewer than two elements is trivially a wiggle sequence.
For example, [1,7,4,9,2,5] is a wiggle sequence because the differences (6,3,5,7,3) are alternately positive and negative. In contrast, [1,4,7,2,5] and [1,7,4,5,5] are not wiggle sequences, the first because its first two differences are positive and the second because its last difference is zero.
Given a sequence of integers, return the length of the longest subsequence that is a wiggle sequence. A subsequence is obtained by deleting some number of elements (eventually, also zero) from the original sequence, leaving the remaining elements in their original order.
Examples:
1  Input: [1,7,4,9,2,5] 
1  class Solution { 
Arithmetic Slices
A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.
1  For example, these are arithmetic sequence: 
Example:
1  A = [1, 2, 3, 4] 
1  class Solution { 
Regular Expression Matching
Given an input string (s) and a pattern (p), implement regular expression matching with support for ‘.’ and ‘*’.
1  '.' Matches any single character. 
Note:
 s could be empty and contains only lowercase letters az.
 p could be empty and contains only lowercase letters az, and characters like . or *.
Example 1:
1  Input: 
Example 2:
1  Input: 
Example 3:
1  Input: 
Example 4:
1  Input: 
Example 5:
1  Input: 
1  class Solution { 
Wildcard Matching
Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for ‘?’ and ‘*’.
‘?’ Matches any single character.
‘*’ Matches any sequence of characters (including the empty sequence).
The matching should cover the entire input string (not partial).
Note:
s could be empty and contains only lowercase letters az.
p could be empty and contains only lowercase letters az, and characters like ? or *.
Example 1:
1  Input: 
Example 2:
1  Input: 
Example 3:
1  Input: 
Example 4:
1  Input: 
Example 5:
1  Input: 
1  class Solution { 
Length of Longest Fibonacci Subsequence
A sequence X_1, X_2, …, X_n is fibonaccilike if:
 n >= 3
 X_i + X_{i+1} = X_{i+2} for all i + 2 <= n
Given a strictly increasing array A of positive integers forming a sequence, find the length of the longest fibonaccilike subsequence of A. If one does not exist, return 0.
(Recall that a subsequence is derived from another sequence A by deleting any number of elements (including none) from A, without changing the order of the remaining elements. For example, [3, 5, 8] is a subsequence of [3, 4, 5, 6, 7, 8].)
Example 1:
1  Input: [1,2,3,4,5,6,7,8] 
Example 2:
1  Input: [1,3,7,11,12,14,18] 
1  class Solution { 
背包
Ones and Zeroes
In the computer world, use restricted resource you have to generate maximum benefit is what we always want to pursue.
For now, suppose you are a dominator of m 0s and n 1s respectively. On the other hand, there is an array with strings consisting of only 0s and 1s.
Now your task is to find the maximum number of strings that you can form with given m 0s and n 1s. Each 0 and 1 can be used at most once.
Note:
 The given numbers of 0s and 1s will both not exceed 100
 The size of given string array won’t exceed 600.
Example 1:
1  Input: Array = {"10", "0001", "111001", "1", "0"}, m = 5, n = 3 
Example 2:
1  Input: Array = {"10", "0", "1"}, m = 1, n = 1 
1  class Solution { 
Partition Equal Subset Sum
Given a nonempty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.
Note:
 Each of the array element will not exceed 100.
 The array size will not exceed 200.
Example 1:
1  Input: [1, 5, 11, 5] 
Example 2:
1  Input: [1, 2, 3, 5] 
1  class Solution { 
最长回文子序列
1 

回文子序列个数
1 
