![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode/动态规划
LUCASYAN个
这个作者很懒,什么都没留下…
展开
-
leetcode 303. Range Sum Query - Immutable
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]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumRan原创 2017-04-24 21:01:32 · 168 阅读 · 0 评论 -
673. Number of Longest Increasing Subsequence 最长递增子序列的个数
Given an unsorted array of integers, find the number of longest increasing subsequence.Example 1:Input: [1,3,5,4,7]Output: 2Explanation: The two longest increasing subsequence are [1, 3, 4, 7]原创 2017-09-22 10:55:35 · 1674 阅读 · 0 评论 -
467. Unique Substrings in Wraparound String
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz", so s will look like this: "...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd....".Now we have原创 2017-09-22 09:58:08 · 278 阅读 · 0 评论 -
动态规划之极小化极大值问题 375. Guess Number Higher or Lower II
这类题目思想是两层极值问题。比如要求求出一个极大值,而这个极大值的选择是在众多的极小值中选择的。1、375. Guess Number Higher or Lower II在1~n中给定一个数,要求猜测这个数是多少,最后猜出这个数的代价是之前猜的数的和。在374类似问题中,是求解最少的猜测次数,使用二分法的思想。这个题目如果受这种思想的限制,就想不到一个合适的解法。回归到最一般原创 2017-09-20 17:26:28 · 1293 阅读 · 1 评论 -
分金子(360公司2017春招真题) 纸牌博弈问题 程序员代码面试指南
A、B两伙马贼意外地在一片沙漠中发现了一处金矿,双方都想独占金矿,但各自的实力都不足以吞下对方,经过谈判后,双方同意用一个公平的方式来处理这片金矿。处理的规则如下:他们把整个金矿分成n段,由A、B开始轮流从最左端或最右端占据一段,直到分完为止。 马贼A想提前知道他们能分到多少金子,因此请你帮忙计算他们最后各自拥有多少金子?(两伙马贼均会采取对己方有利的策略)输入原创 2017-09-18 20:00:56 · 920 阅读 · 0 评论 -
368. Largest Divisible Subset
Given an encoded string, return it's decoded string.The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is原创 2017-09-16 09:03:20 · 222 阅读 · 0 评论 -
416. Partition Equal Subset Sum 类似最小不可组成和
Given a non-empty 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原创 2017-09-16 08:59:39 · 237 阅读 · 0 评论 -
309. 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 on原创 2017-09-16 08:59:15 · 205 阅读 · 0 评论 -
524. Longest Word in Dictionary through Deleting
Given a string and a string dictionary, find the longest string in the dictionary that can be formed by deleting some characters of the given string. If there are more than one possible results, retur原创 2017-09-16 09:00:42 · 179 阅读 · 0 评论 -
646. Maximum Length of Pair Chain 类似与最长子序列但是有简单做法 贪心方法
You are given n pairs of numbers. In every pair, the first number is always smaller than the second number.Now, we define a pair (c, d) can follow another pair (a, b) if and only if b . Chain原创 2017-09-07 22:46:25 · 239 阅读 · 0 评论 -
542. 01 Matrix 寻找最近的0 重点 BFS 动态规划
Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell.The distance between two adjacent cells is 1.Example 1: Input:0 0 00 1 00 0 0Output:0 0 00 1 00原创 2017-09-15 10:52:59 · 588 阅读 · 0 评论 -
638. Shopping Offers 深度优先遍历、递归、存储技术(基于递归的动态规划)
Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum number of length k from digits of the two. The relative order of the digits from the same array must原创 2017-09-05 00:07:56 · 252 阅读 · 0 评论 -
264. Ugly Number II 剑指offer
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, 6, 8, 9, 10, 12 is the sequence of the first原创 2017-09-13 14:05:21 · 165 阅读 · 0 评论 -
leetcode 304. Range Sum Query 2D - Immutable 序列和+动态规划
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 (row2, col2).The above rectangle (with the red bo原创 2017-04-24 22:12:32 · 240 阅读 · 0 评论 -
115. Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of S which equals T.A subsequence of a string is a new string which is formed from the original string by deleting some (ca原创 2017-09-22 16:30:30 · 265 阅读 · 0 评论