4.17 leetcode -17 longest-substring-without-repeating-characters
来源:互联网 发布:windows无法连接到cmcc 编辑:程序博客网 时间:2024/06/11 04:13
题目描述
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.
这个题目就比较有意思了,最小子串,里面不能包含重复的字符。
我觉得用桶(或者map)就能做.
class Solution {public: int lengthOfLongestSubstring(string s) { bool btong[255]; for(int i = 0;i < 255;i++) btong[i] = false; int nlength = s.length(); int start = 0; int nmax = 0; for(int i = 0;i < nlength;i++) { if(btong[s[i]] == false) btong[s[i]] = true; else { if((i-start) > nmax) nmax = (i-start); while(s[start] != s[i]) { btong[s[start]] = false; start ++; } start ++; } } if((nlength-start) > nmax) nmax = (nlength-start); return nmax; }};
阅读全文
0 0
- 4.17 leetcode -17 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
- LeetCode 3: Longest Substring Without Repeating Characters
- leetcode-3:Longest Substring Without Repeating Characters
- HBase RPC理解之一
- Java 正则表达式
- 2017暑假第二阶段第七场 总结
- Java数组
- mysql连接问题1045 Access denied for user 'root'@'localhost' (using password:YES)
- 4.17 leetcode -17 longest-substring-without-repeating-characters
- ubuntu16.04mailcatcher
- FBO
- 如何选择最好的关键词,让客户容易搜索到?
- 技术文章 | Laravel/Lumen搭建服务器性能测试
- [贪心+深搜]马的回路
- Directx9学习(六)第一个小游戏
- 安装RHadoop
- wireshark监控android socket 通信