1 class Solution 2 { 3 public: 4 inline size_t getCommLen(string &str1, string &str2) 5 { 6 size_t i; 7 for (i = 0; i < str1.size() && i < str2.size(); i++) 8 { 9 if (str1[i] != str2[i])10 bre
题目:https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/ 给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。 法一: def lengthOfLongestSubstring(s): listi = [] if len(s) in [0,1]: return len(s) else:
//方法一:使用HashMap记录字符的位置,实现滑动窗口 public class LengthOfLongestSubstring {public int lengthOfLonggestSubstring(String s) { if(s == null) { throw new IllegalArgumentException(); }else { Map<Character, Integer> map = new
这题二分加HASH 6-7秒,如果能用unordered_map,5秒。后缀自动机200-400ms。后缀数组(没写)大概2000ms。 #include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#include <vector>#include <iomanip>#include <cstring>#include <map
1 class Solution(object): 2 def getMaxByCount(self,A,maxlen): 3 curmax = 0 4 curmax = sum(A[:maxlen]) 5 bigmax = curmax 6 n = len(A) 7 for i in range(maxlen,n): 8 curmax = curmax-A[i-maxlen]+A[i] 9
Input: "abcabcbb"Output: 3 Explanation: The answer is "abc", with the length of 3. Input: "bbbbb"Output: 1Explanation: The answer is "b", with the length of 1. Input: "pwwkew"Output: 3Explanation: The
题目: 给定一个只包含 '(' 和 ')' 的字符串,找出最长的包含有效括号的子串的长度。 分析: 这道题在我半年前开始学算法的时候有写过,不过最后绝对是被虐哭了,主要原因就是无法解决当你向下遍历字符串的时候,遇到隔断后再将其消除不能和上一个连续的有效字串合并。 现在在学了一些算法
给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。 示例 1: 输入: "abcabcbb"输出: 3 解释: 因为无重复字符的最长子串是 "abc",所以其长度为 3。 示例 2: 输入: "bbbbb"输出: 1解释: 因为无重复字符的最长子串是 "b",所以其长度为 1。 示例 3: 输入: "pwwkew"
方法一: class Solution { public: string longestPalindrome(string s) { if (s.size() < 2) return s; int n = s.size(), maxLen = 0, start = 0; for (int i = 0; i < n - 1; ++i) { searchPalindrome(s, i, i
思路 后缀数组+博弈论的好题,首先对两个串都建出SAM,然后题目的要求实际上就是在SAM的trans上转移即可 DAG的博弈是经典问题,然后dfs求出SG函数,两个游戏的组合就是把SG函数异或起来,异或是0就是先手必败,不是0就是先手必胜 然后要求先手必胜,所以就是求异或不为0 接下来递推的求出第k大的
这题就没得暴力前缀和了(老老实实打DP) 输入样例 7 1 7 3 5 9 4 8 输出样例 4 解题思路 1.找子问题 “求序列的前n个元素的最长上升子序列的长度”是个子问题,但这样分解子问题,不具有“无后效性”,因为假设F(n) = x,但可
1 int lengthOfLongestSubstring(char *s) 2 { 3 int size = strlen(s);/*字符串长度*/ 4 int dict[256] = {0}; 5 for(int i=0; i<256; ++i) 6 dict[i] = -1; 7 int maxlen = 0;/*最大无重复字符串长度*/ 8 int start = -1;/*无重复字符