Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1. 这道题看似简单。可是用遍历...
5. Longest Palindromic Substring Total Accepted: 120226 Total Submissions: 509522 Difficulty: Medium Given a string s, find the longest palindromic(回文) substring in sS. You may assume that the maximum length of s is 1000, and there exists one unique longest palindromic substring. 推荐解法3,直...
Given a stringS, find the longest palindromic substring inS. You may assume that the maximum length ofSis 1000, and there exists one unique longest palindromic substring. 最长回文子串。 有两种思路: 1,从左向右找对称点,从对称点(或者两个相同的相邻字符)向两边搜索,记下搜到的最大长度。 2,设置一...
publicclassSolution{publicintlengthOfLongestSubstring(String s){intlength=s.length();intmaxLength=0;intslow=0,pos=0;HashMap<Character,Integer>map=newHashMap<>();for(inti=0;i<length;i++){if(map.containsKey(s.charAt(i))){pos=map.get(s.charAt(i));if(pos>=slow){maxLength=Math.max(i-...
Output:[] 解题思路:用两个map分别记录字典单词数量和使用的单词数量。当单词的使用量大于字典数量,或者连续截取单词不在字典中,则返回失败。 vector<int> findSubstring(strings, vector<string>&words) { vector<int>results;if(s.size()==0|| words.size()==0)returnresults; ...