Leetcode 159. Longest Substring with At Most Two Distinct Characters (Hard) (cpp)
来源:互联网 发布:linux wget https 404 编辑:程序博客网 时间:2024/04/30 19:15
Leetcode 159. Longest Substring with At Most Two Distinct Characters (Hard) (cpp)
Tag: Hash Table, Two Pointers, String
Difficulty: Hard
/*159. Longest Substring with At Most Two Distinct Characters (Hard)Given a string, find the length of the longest substring T that contains at most 2 distinct characters.For example, Given s = “eceba”,T is "ece" which its length is 3.*/class Solution {public:int lengthOfLongestSubstringTwoDistinct(string s) {if (s.size() < 3) {return s.size();}vector<int> t(256, 0);int sl = 0, f = 0, res = 0, cnt = 0;while (f < s.size()) {if (++t[s[f++]] == 1) {cnt++;}while (cnt > 2) {--t[s[sl++]];if (t[s[sl - 1]] == 0) {cnt--;}}res = max(f - sl, res);}return res;}};
0 0
- Leetcode 159. Longest Substring with At Most Two Distinct Characters (Hard) (cpp)
- Leetcode-159.Longest Substring with At Most Two Distinct Characters
- Leetcode-159.Longest Substring with At Most Two Distinct Characters
- [LeetCode]159. Longest Substring with At Most Two Distinct Characters
- LeetCode 159. Longest Substring with At Most Two Distinct Characters
- Leetcode 159. Longest Substring with At Most Two Distinct Characters
- [Leetcode] Longest Substring with At Most Two Distinct Characters
- Leetcode Longest Substring with At Most Two Distinct Characters
- leetcode 159: Longest Substring with At Most Two Distinct Characters
- [Leetcode]Longest Substring with At Most Two Distinct Characters
- LeetCode - Longest Substring with At Most Two Distinct Characters
- Leetcode: Longest Substring with At Most Two Distinct Characters
- Leetcode 159 Longest Substring with At Most Two Distinct Characters
- Leetcode 159 Longest Substring with At Most Two Distinct Characters
- 159. Longest Substring with At Most Two Distinct Characters
- 159. Longest Substring with At Most Two Distinct Characters
- [leetcode] 159. Longest Substring with At Most Two Distinct Characters 解题报告
- LeetCode 159. Longest Substring with At Most Two Distinct Characters(最长字串)
- Pynlpir词性标记集
- 三分钟看懂一致性哈希算法
- Hamming Distance
- 复杂HTML代码深度解析
- golang编译arm平台程序
- Leetcode 159. Longest Substring with At Most Two Distinct Characters (Hard) (cpp)
- Ajax中的eval函数的用法
- oracle 修改默认日期格式
- Web 前端学习笔记之 HTML 入门(3)
- 2016.12.29回顾
- 东周列国 演绎版 mp3
- Java学习笔记(二十六):String.split()的使用
- ZCMU-1140-松哥
- Caffe installation on ubuntu16.04 sever