Dynamic Programming
文章平均质量分 74
violet_program
这个作者很懒,什么都没留下…
展开
-
Word Break II
// DFS + Memorization public ArrayList wordBreak(String s, Set dict) { // Note: The Solution object is instantiated only once and is reused by // each test case. // min and max length of words原创 2013-10-09 11:49:44 · 2003 阅读 · 0 评论 -
Two Sum
import java.util.Hashtable;public class Solution { public int[] twoSum(int[] numbers, int target) { // Start typing your Java solution below // DO NOT write main() function int[] res = {0,原创 2013-04-01 09:07:13 · 658 阅读 · 4 评论 -
Palindrome Partitioning I
public class Solution { ArrayList> res; ArrayList partition; public ArrayList> partition(String s) { // Start typing your Java solution below // DO NOT write main() function res = new Arra原创 2013-05-07 05:13:55 · 639 阅读 · 0 评论 -
Leetcode: Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?public class Solut原创 2013-07-15 05:56:44 · 442 阅读 · 0 评论 -
Palindrome Partitioning II
public class Solution { public int minCut(String s) { // Start typing your Java solution below // DO NOT write main() function int len = s.length(); int[] res = new int[len + 1]; // res[转载 2013-05-08 04:37:35 · 531 阅读 · 0 评论 -
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 yo原创 2013-06-08 01:47:30 · 482 阅读 · 0 评论 -
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原创 2013-06-11 04:58:54 · 419 阅读 · 0 评论 -
Edit Distance
Given two words word1 and word2, find the minimum number of steps required to convertword1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:原创 2013-06-13 12:04:55 · 475 阅读 · 0 评论 -
Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total number原创 2013-06-21 05:04:17 · 564 阅读 · 0 评论 -
Leetcode: Interleaving String
Given s1, s2, s3, find whether s3 is formed by the interleaving ofs1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", return原创 2013-06-29 02:06:55 · 523 阅读 · 0 评论 -
Leetcode: Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences ofT in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none原创 2013-07-12 10:51:55 · 624 阅读 · 0 评论 -
Leetcode: Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]public class Solution { p原创 2013-07-15 05:11:22 · 460 阅读 · 0 评论 -
Jump Game II
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.Your goal is to原创 2013-05-28 12:23:00 · 511 阅读 · 0 评论 -
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.原创 2013-06-11 05:13:14 · 489 阅读 · 0 评论 -
Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right whichminimizes the sum of all numbers along its path.Note: You can only move either down or right at原创 2013-06-11 10:24:24 · 497 阅读 · 0 评论 -
Climbing Stairs
You 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?public class Solution {原创 2013-06-13 10:43:01 · 440 阅读 · 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,原创 2013-07-15 11:21:43 · 525 阅读 · 0 评论 -
Word Break
/* * Given a string s and a dictionary of words dict, * determine if s can be segmented into a space-separated sequence * of one or more dictionary words. * * For example, given * s = "le原创 2013-10-09 09:58:18 · 783 阅读 · 0 评论 -
3Sum
public class Solution { public ArrayList> threeSum(int[] num) { // Start typing your Java solution below // DO NOT write main() function ArrayList> res = new ArrayList>(); if(num.length ==原创 2013-04-02 05:21:52 · 541 阅读 · 0 评论