随笔分类 -  动态规划(DP)

摘要:题目:Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.For example, given n = 1... 阅读全文
posted @ 2015-12-13 09:35 lasclocker 阅读(162) 评论(0) 推荐(0)
摘要:题目:Write a program to find the nth super ugly number.Super ugly numbers are positive numbers whose all prime factors are in the given prime list prime... 阅读全文
posted @ 2015-12-04 21:25 lasclocker 阅读(557) 评论(0) 推荐(0)
摘要:题目:Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5... 阅读全文
posted @ 2015-12-04 21:16 lasclocker 阅读(481) 评论(0) 推荐(0)
摘要:题目:Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the ball... 阅读全文
posted @ 2015-12-01 10:18 lasclocker 阅读(877) 评论(0) 推荐(0)
摘要:题目: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 comp... 阅读全文
posted @ 2015-11-28 21:57 lasclocker 阅读(1037) 评论(0) 推荐(0)
摘要:题目: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 comp... 阅读全文
posted @ 2015-11-26 13:56 lasclocker 阅读(156) 评论(0) 推荐(0)
摘要:题目: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 comp... 阅读全文
posted @ 2015-11-26 12:25 lasclocker 阅读(140) 评论(0) 推荐(0)
摘要:题目: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 transacti... 阅读全文
posted @ 2015-11-25 18:12 lasclocker 阅读(202) 评论(0) 推荐(0)
摘要:题目:Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (r... 阅读全文
posted @ 2015-11-14 19:47 lasclocker 阅读(1286) 评论(0) 推荐(0)
摘要:题目:Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumR... 阅读全文
posted @ 2015-11-11 15:13 lasclocker 阅读(241) 评论(0) 推荐(0)
摘要:该题来自leetcode,原题如下:You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only cons... 阅读全文
posted @ 2015-10-18 20:04 lasclocker 阅读(968) 评论(0) 推荐(0)
摘要:斐波那契数列:1, 1, 2, 3, 5, 8, 13,...,即 f(n) = f(n-1) + f(n-2). 求第n个数的值。方法一:迭代 public static int iterativeFibonacci(int n) { //简单迭代 int a = 1, b =... 阅读全文
posted @ 2015-10-18 14:26 lasclocker 阅读(553) 评论(0) 推荐(0)