We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。
输入: "abcabcbb" 输出: 3 解释: 因为无重复字符的最长子串是 "abc",所以其长度为 3。
输入: "bbbbb" 输出: 1 解释: 因为无重复字符的最长子串是 "b",所以其长度为 1。
输入: "pwwkew" 输出: 3 解释: 因为无重复字符的最长子串是 "wke",所以其长度为 3。 请注意,你的答案必须是 子串 的长度,"pwke" 是一个子序列,不是子串。
来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/longest-substring-without-repeating-characters
// 此题可用滑动窗口来解答,这个窗口不允许包含重复的字符。这样可以用指针 i 来表示窗口的左侧,j 来表示窗口的右侧,依次从左侧遍历,如果窗口中没有包含字符,则j++, i不变。如果 i++,j 不变。 func lengthOfLongestSubstring(s string) int { if s == "" { return 0 } i, j, ret, l := 0, 0, 0, len(s) var maxS string for i < l && j < l { if !strings.ContainsRune(maxS, rune(s[j])) { j++ } else { i++ } maxS = s[i:j] if len(maxS) > ret { ret = len(maxS) } } return ret }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。
示例 1:
示例 2:
示例 3:
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/longest-substring-without-repeating-characters
The text was updated successfully, but these errors were encountered: