leetcode---longest-substring-without-repeating-characters---字符串
来源:互联网 发布:linux mmap使用 编辑:程序博客网 时间:2024/09/21 06:22
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.
class Solution {public: int max(int a, int b) { return a > b ? a : b; } int lengthOfLongestSubstring(string s) { bool exist[27]; int pos[27]; memset(exist, false, sizeof(exist)); memset(pos, 0, sizeof(pos)); int start = 0; int maxLen = 0; for(int i=0; i<s.size(); i++) { int cur = s[i] - 'a'; if(exist[cur]) { for(int j=start; j<=pos[cur]; j++) exist[s[j]-'a'] = false; start = pos[cur] + 1; exist[cur] = true; pos[cur] = i; } else { exist[cur] = true; pos[cur] = i; maxLen = max(maxLen, i-start+1); } } return maxLen; }};
阅读全文
0 0
- leetcode---longest-substring-without-repeating-characters---字符串
- LeetCode--Longest Substring Without Repeating Characters(字符串Hash)
- LeetCode练习-字符串-longest-substring-without-repeating-characters
- LeetCode: Longest Substring Without Repeating Characters
- LeetCode Longest Substring Without Repeating Characters
- LeetCode: Longest Substring Without Repeating Characters
- [Leetcode] Longest Substring Without Repeating Characters
- leetcode 23: Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- LeetCode 3 - Longest Substring Without Repeating Characters
- [LeetCode]Longest Substring Without Repeating Characters
- leetcode Longest Substring Without Repeating Characters
- 【leetcode】 Longest Substring Without Repeating Characters
- LeetCode-Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- [leetcode] Longest Substring Without Repeating Characters
- LeetCode - Longest Substring Without Repeating Characters
- Qt5与https
- 第十五天总结
- Retrofit结合rxjava使用
- Mvp使用
- iOS推送javaPNS源码解析四,证书管理类
- leetcode---longest-substring-without-repeating-characters---字符串
- linux——线程
- HTML5动画和鼠标移动
- TCP/IP 关于一些在应用层的协议
- 先码后看 Tomcat是怎么启动的?——Bootstrap引导 侵立删
- ThreeQieHuan
- -lrt问题,即:shm_open的头文件存在,编译却不通过,提示undefined
- 数据结构笔记(一)线性表的顺序表示和基本操作及其顺序表实现的集合运算(A-B)U(B-A)实例
- baidua