Leetcode(3)之无重复字符的最长子串
2019-12-30 16:29
561 查看
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>
题目描述:
解题思路:
维护一个Queue和最大长度ret,遍历s中每个char时如果Queue中包含char就一直Dequeue,Dequeue完之后将当前的charEnqueue,如果此时Queue的Count大于ret就替代ret。
代码:
public int LengthOfLongestSubstring(string s) { Queue<char> queue = new Queue<char>(); int ret = 0; foreach (char c in s) { while (queue.Contains(c)) { queue.Dequeue(); } queue.Enqueue(c); if (queue.Count > ret) ret = queue.Count; } return ret; }
相关文章推荐
- leetcode 3. 无重复字符的最长子串(Java 版)
- LeetCode3. 无重复字符的最长子串(Java)
- LeetCode第三题无重复字符的最长子串
- Leetcode 3. 无重复字符的最长子串
- leetcode 3. 无重复字符的最长子串
- leetcode(3)无重复字符的最长子串
- LeetCode--3.Longest Substring Without Repeating Characters(无重复字符的最长子串)
- [leetcode]无重复字符的最长子串
- Leetcode3-无重复字符的最长子串
- LeetCode[3] 无重复字符的最长子串
- leetcode第三题无重复字符的最长子串的java实现
- LeetCode: 3_Longest Substring Without Repeating Characters | 求没有重复字符的最长子串的长度 | Medium
- LeetCode3 无重复字符的最长子串 Longest Substring Without Repeating Characters
- LeetCode给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。
- LeetCode 无重复字符的最长子串
- LeetCode-3-无重复字符的最长子串
- 【leetcode】3. 无重复字符的最长子串
- leetcode 3 无重复字符的最长子串
- leetcode 3 无重复字符的最长子串
- [Leetcode] 3.无重复字符的最长子串