128. Longest Consecutive Sequence hashmap, int up = nums[i], int down, int max 注:访问过的要erase 152. Maximum Product Subarray Maximum Subarray那题的变种.由于正负得负,负负得正的关系.以A[i]结尾的max product subarray同时取决于以A[i-1]结尾的max / min product subarray以及A[i]本身.因此,对每个i,需要记录m…
转载自leetcode评论区:https://discuss.leetcode.com/topic/30941/here-is-a-10-line-template-that-can-solve-most-substring-problems I will first give the solution then show you the magic template. The code of solving this problem is below. It might be the shor…
463. Island Perimeterhttps://leetcode.com/problems/island-perimeter/就是逐一遍历所有的cell,用分离的cell总的的边数减去重叠的边的数目即可.在查找重叠的边的数目的时候有一点小技巧,就是沿着其中两个方向就好,这种题目都有类似的规律,就是可以沿着上三角或者下三角形的方向来做.一刷一次ac,但是还没开始注意codestyle的问题,需要再刷一遍. class Solution { public: int islandPerime…
Given a string S, find the number of different non-empty palindromic subsequences in S, and return that number modulo 10^9 + 7. A subsequence of a string S is obtained by deleting 0 or more characters from S. A sequence is palindromic if it is equal…
Given a string, your task is to count how many palindromic substrings in this string. The substrings with different start indexes or end indexes are counted as different substrings even they consist of same characters. Example 1: Input: "abc" Ou…
Given a string S, find the number of different non-empty palindromic subsequences in S, and return that number modulo 10^9 + 7. A subsequence of a string S is obtained by deleting 0 or more characters from S. A sequence is palindromic if it is equal…
Given a string, your task is to count how many palindromic substrings in this string. The substrings with different start indexes or end indexes are counted as different substrings even they consist of same characters. Example 1: Input: "abc" Ou…
D2. Kirk and a Binary String (hard version) time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output The only difference between easy and hard versions is the length of the string. You can hack this pro…
专题6--动态规划 1.动态规划基础知识 什么情况下可能是动态规划?满足下面三个条件之一:1. Maximum/Minimum -- 最大最小,最长,最短:写程序一般有max/min.2. Yes/No----是否可行:写程序一般有||.3. Count(*)--数方案的个数,比如有多少条路径这种.初始化0个的情况下,初始化为1,联想组合数学里面0! = 1.则 “极有可能”是使用动态规划求解.什么情况下可能不是动态规划? 1)如果题目需要求出所有 “具体 ”的方案而非方案 “个数 ”: 2)输…
StringBuffer 其实提供了很多有用的方法, 以前用的多是 append, 其实还有: append(double) delete(int, int) deleteCharAt(int) replace(int, int, String) substring(int) subSequence(int, int) substring(int, int) insert(int, char[], int, int) insert(int, Object) insert(int, String)…