#Longest

LeetCode:14. Longest Commen Prefix(Easy)

https://leetcode.com/problems/longest-common-prefix/description/  给定一个字符串数组,让你求出该数组中所有字符串的最大公共前缀。例如{"qqwwee","qqww","qqfds"}的最大公共前缀为"qq",{"qqwwee","qq...

LeetCode:5. Longest Palindromic Substring(Medium)

原题链接:https://leetcode.com/problems/longest-palindromic-substring/description/1.题目要求:找出字符串中的最大回文子串 2.注意:要考虑回文子串中的字符个数是奇数还是偶数!!!例如,“aabaa”是一个奇数个字符的回文字符串,他的中心...

LeetCode:3.Longest Substring Without Repeating Characters

思路:看到题目首先想到最大字符串匹配KMP算法1publicstaticintlengthOfLongestSubstring(Strings){2intmaxLength=0;3StringBuildersb=newStringBuilder(s);4a:for(inti=0;i<sb.length();i++...

leetcode 329. Longest Increasing Path in a Matrix

329.LongestIncreasingPathinaMatrixhttps://www.cnblogs.com/grandyang/p/5148030.html这个题是在二维数组中找递增序列的最长长度。因为使用dfs都是从当前位置进行搜索,所以每次dp计算的值是以当前为起点的最长长度。这里使用了一个二维数组记录每个...

leetcode 395. Longest Substring with At Least K Repeating Characters

395.LongestSubstringwithAtLeastKRepeatingCharactershttps://www.cnblogs.com/grandyang/p/5852352.html题目的要求是找一段字符串,这段字符串中每个单词出现的次数都必须至少超过k次,求满足这种条件的字符串的最长的长度。暴力的方法...

5. Longest Palindromic Substring

https://www.cnblogs.com/grandyang/p/4464476.html用动态规划做classSolution{public:stringlongestPalindrome(strings){if(s.empty())return"";intdp[s.size()][s.size()]={0};...
代码星球 代码星球·2020-10-13

128. Longest Consecutive Sequence

 https://www.cnblogs.com/grandyang/p/4276225.html把数组中所有的数按照值存储到set中,然后在set中找相邻的值以获得这个区间先把所有值存储在set中,然后减去的方式,这样可以避免重复计算时间复杂度如果换成set就是n*logn为什么这个是o(n)常规的题中经常...

leetcode 20. Valid Parentheses 、32. Longest Valid Parentheses 、301. Remove Invalid Parentheses

20.ValidParentheses 错误解法:"[])"就会报错,没考虑到出现')'、']'、'}'时,stack为空的情况,这种情况也无法匹配classSolution{public:boolisValid(strings){if(s.empty())returnfalse;stack<char&...

leetcode 3. Longest Substring Without Repeating Characters

用unordered_map存储字符和字符对应的索引。left是上一个重复字符的位置索引,初始为-1,因为最开始没有重复字符,如果初始为0,就表示第0个位置重复了,显然不符合题意。同时你也可以用i-left计算发现,如果前面没有重复,你的left初始化为0,计算就少1了。注意:if判断中要m[s[i]]>left...

leetcode300. Longest Increasing Subsequence 最长递增子序列 、674. Longest Continuous Increasing Subsequence

 LongestIncreasingSubsequence最长递增子序列 子序列不是数组中连续的数。dp表达的意思是以i结尾的最长子序列,而不是前i个数字的最长子序列。初始化是dp所有的都为1,最终的结果是求dp所有的数值的最大值。 classSolution{public:intleng...

lintcode 77.Longest Common Subsequence(最长公共子序列)、79. Longest Common Substring(最长公共子串)

LongestCommonSubsequence最长公共子序列:每个dp位置表示的是第i、j个字母的最长公共子序列classSolution{public:intfindLength(vector<int>&A,vector<int>&B){intlen1=A.size();in...

300. Longest Increasing Subsequence

这个题用DP,千万不能将state设为f[i]表示前i个数字中最长的LIS的长度,而是设成f[i]表示前i个数字中以第i个结尾的LIS的长度。如果那样定义,f[i]和f[j]之间是没有太大关系。比如7,8,10,2,3,4,5可以,但2,3,9,10,5,6,7,8就不行因为f[i]表示前i个数字中以第i个结尾的LIS...

1040 Longest Symmetric String (25分)(dp)

Givenastring,youaresupposedtooutputthelengthofthelongestsymmetricsub-string.Forexample,given IsPAT&TAPsymmetric?,thelongestsymmetricsub-stringis s...

leetcode 14-> Longest Common Prefix

 note:Allgiveninputsareinlowercaseletters a-z.classSolution(object):deflongestCommonPrefix(self,strs):""":typestrs:List[str]:rtype:str"""iflen(strs)==...

leetcode 5-> Longest Palindromic Substring

 classSolution(object):defget_f_l(self,s_length,s,list_all,last_d):max_l=0first_d=0last_d=0foriinrange(len(list_all)):if((i+1)==len(list_all)):breakforjinr...
首页上一页12下一页尾页