
动态规划
子长
这个作者很懒,什么都没留下…
展开
-
62. 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 botto原创 2017-11-08 01:19:01 · 186 阅读 · 0 评论 -
算法期中1003. 最近的0
Description 输入一个N*M的01矩阵A,对矩阵的每个位置,求至少经过多少步可以到达一个0. 每一步可以往上下左右走一格.请为下面的Solution类实现解决这一问题的函数nearestZero,函数参数A为给出的01矩阵,A的行数和列数均不大于100. 函数的返回值是问题的答案.class Solution { public: vector<vector<int>>neares原创 2017-11-13 20:04:08 · 251 阅读 · 0 评论 -
5. Longest Palindromic Substring
问题Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example:Input: “babad”Output: “bab”Note: “aba” is also a valid answer. Example:Inpu原创 2017-12-18 18:31:02 · 161 阅读 · 0 评论 -
1006. 最长公共子串
未结束,还没理解清楚,溜去睡觉了。Description 给定两个字符串x = x1x2…xn和y = y1y2…ym, 请找出x和y的最长公共子串的长度,也就是求出一个最大的k,使得存在下标i和j有xixi+1…xi+k-1 = yjyj+1…yj+k-1.x和y只含有小写字母,长度均在1和1000之间.请为下面的Solution类实现解决上述问题的函数longestSubs原创 2017-11-13 20:55:47 · 306 阅读 · 0 评论 -
474. Ones and Zeroes
题目:In the computer world, use restricted resource you have to generate maximum benefit is what we always want to pursue.For now, suppose you are a dominator of m 0s and n 1s respectively. On the other原创 2017-12-03 11:04:09 · 192 阅读 · 0 评论 -
688. Knight Probability in Chessboard
https://leetcode.com/problems/knight-probability-in-chessboard/description/ On an NxN chessboard, a knight starts at the r-th row and c-th column and attempts to make exactly K moves. The rows and col原创 2017-11-04 22:53:42 · 316 阅读 · 0 评论 -
53. Maximum Subarray (9月12日)
53. 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 subarra原创 2017-09-11 21:10:14 · 207 阅读 · 0 评论 -
算法期中1005. 最小和
Description 从数列A[0], A[1], A[2], …, A[N-1]中选若干个数,要求对于每个,i(i >= 0, i <=N - 1)A[i]和A[i+1]至少选一个数,求能选出的最小和.1 <= N <= 100000, 1 <= A[i] <= 1000请为下面的Solution类实现解决上述问题的函数minSum,函数参数A是给出的数列,返回值为所求的最小和.class S原创 2017-11-13 19:03:10 · 259 阅读 · 0 评论 -
121. Best Time to Buy and Sell Stock
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 transaction (ie, buy one and sell one share of the stock), desi转载 2017-11-02 00:34:05 · 173 阅读 · 0 评论 -
70. 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?Note: Given n will be a positive inte原创 2017-11-02 23:42:37 · 167 阅读 · 0 评论 -
198. House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses原创 2017-10-31 23:50:47 · 169 阅读 · 0 评论 -
309. Best Time to Buy and Sell Stock with Cooldown
题目 class Solution { public: int maxProfit(vectorint>& prices) { int buy = INT_MIN; int pre_buy; int sell = 0; int pre_sell = 0; for (int i = 0; i < pri转载 2018-01-11 16:24:22 · 211 阅读 · 0 评论