標籤:: DynamicProgramming

0

Largest Divisible Subset

Largest Divisible SubsetGiven 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

0

Count Numbers with Unique Digits

Count Numbers with Unique DigitsGiven a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10^n. For example:1Given n = 2, return 91. (The answer should be the total nu

0

Integer Break

Integer BreakGiven a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get. For example:1Given

0

Counting Bits

Counting BitsGiven 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. For example:

0

Coin Change

Coin ChangeYou are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amou

0

Best Time to Buy and Sell Stock with Cooldown

Best Time to Buy and Sell Stock with CooldownSay 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 a

0

Range Sum Query 2D - Immutable

Range Sum Query 2D - ImmutableGiven 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 (row2, col2). The abov

0

Longest Increasing Subsequence

Longest Increasing SubsequenceGiven an unsorted array of integers, find the length of longest increasing subsequence. For example:Given [10, 9, 2, 5, 3, 7, 101, 18],The longest increasing subsequence

0

Perfect Squares

Perfect SquaresGiven a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, …) which sum to n. For example:123Given n = 12, return 3 because 12 = 4 + 4 + 4;G

0

Ugly Number II

Ugly Number IIWrite 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, 6, 8, 9, 10, 12 is the sequence of

0

Maximal Square

Maximal SquareGiven a 2D binary matrix filled with 0’s and 1’s, find the largest square containing only 1’s and return its area. For example:Given the following matrix: 12341 0 1 0 01 0 1 1 11 1 1 1

0

House Robber II

House Robber IINote: This is an extension of House Robber. After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attent

0

Maximum Product Subarray

Maximum Product SubarrayFind the contiguous subarray within an array (containing at least one number) which has the largest product. For example:12Given the array [2,3,-2,4],the contiguous subarray [

0

Word Break

Word BreakGiven a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words. Y

0

Triangle

TriangleGiven 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 123456[ [2], [3,4]

0

Unique Binary Search Trees II

Unique Binary Search Trees IIGiven an integer n, generate all structurally unique BST’s (binary search trees) that store values 1…n. For example:Given n = 3, your program should return all 5 unique B

0

Unique Binary Search Trees

Unique Binary Search TreesGiven n, how many structurally unique BST’s (binary search trees) that store values 1…n? For example:Given n = 3, there are a total of 5 unique BST’s. 123451 3 3

0

Minimum Path Sum

Minimum Path SumGiven 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 do

0

Unique Paths II

Unique Paths IIFollow 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

0

Unique Paths

Unique PathsA 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

0

Maximum Subarray

Maximum SubarrayFind 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 [

0

Range Sum Query - Immutable

Range Sum Query - ImmutableGiven an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. For Example:12345Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) ->