Distinct Subsequences leetcode

2016-01-13
阅读 2 分钟
1.8k
Given a string S and a string T, count the number of distinctsubsequences of T in S. A subsequence of a string is a new string which is formed from theoriginal string by deleting some (can be none) of the characterswithout disturbing the relative positions of the remaining characters.(ie, "ACE" i...

Interleaving String leetcode

2016-01-13
阅读 3 分钟
2.4k
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1and s2. For example, Given: s1 = "aabcc", s2 = "dbbca", When s3 = "aadbbcbcac", return true. When s3 = "aadbbbaccc", returnfalse.

Triangle leetcode

2016-01-13
阅读 2 分钟
2.4k
Triangle {代码...} 动态规划 思路 自底向上求解, {代码...} 复杂度 时间O(n^2) 空间O(n^2) 代码 {代码...} 一维动态规划 思路 维护一个长度为n的数组, 每次只更新当前数组 复杂度 时间O(n^2) 空间O(n) 代码 {代码...}

Decode Ways leetcode

2016-01-13
阅读 2 分钟
2.2k
A message containing letters from A-Z is being encoded to numbersusing the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 Given an encoded message containingdigits, determine the total number of ways to decode it. For example, Given encoded message "12", it could be decoded as "AB"(1...

Climbing Stairs leetcode

2016-01-13
阅读 1 分钟
1.7k
state: f[i] 表示爬到第i个楼梯的所有方法的和function: f[i] = f[i-1] + f[i-2] //因为每次走一步或者两步, 所以f[i]的方法就是它一步前和两步前方法加和initial: f[0] = 0; f[1] = 1end : return f[n]

Minimum Path Sum leetcode

2016-01-13
阅读 2 分钟
2k
Given a m x n grid filled with non-negative numbers, find a path fromtop left to bottom right which minimizes the sum of all numbers alongits path. Note: You can only move either down or right at any point in time.

Unique Paths I & II leetcode

2016-01-13
阅读 3 分钟
2.3k
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. Therobot is trying to reach the bottom-right corner of the grid (marked'Finish' in the diagram below). How many possible unique paths ...

Maximum Product Subarray leetcode

2016-01-12
阅读 2 分钟
1.6k
Find the contiguous subarray within an array (containing at least onenumber) which has the largest product. For example, given the array [2,3,-2,4], the contiguous subarray [2,3]has the largest product = 6.

Maximum Subarray leetcode

2016-01-12
阅读 1 分钟
2.3k
Find the contiguous subarray within an array (containing at least onenumber) which has the largest sum. For example, given the array [−2,1,−3,4,−1,2,1,−5,4], the contiguoussubarray [4,−1,2,1] has the largest sum = 6.