Longest Substring Without Repeating Characters
来源:互联网 发布:办公软件应用2003 编辑:程序博客网 时间:2024/05/16 17:45
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.
===================================================================================================================================
找到最长的不重复子字符串,思路就是找个数组保存每个字符出现的次数,大于1时就证明重复了,剪掉之后继续找
int lengthOfLongestSubstring(char* s) { static bool flag[256];memset(flag, false, sizeof(flag));int len = 0, max = 0;for (int i = 0; i <strlen(s); i++){if (!flag[s[i]]){flag[s[i]] = true;len++;}else{int counter = 0;for (int j = i - len;s[j]!=s[i];j++){flag[s[j]]=false;counter++;}len -= counter;}if (max < len){max = len;}}return max;}
0 0
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- 【SQL Server技巧篇】如何使用Transact-SQL脚本语言导入Excel表
- 对于某种无法改变的习性,我感到一种宿命的无奈。
- 轻量级web server Tornado代码分析
- 程序员的量化交易之路(24)--Cointrader之RemoteEvent远程事件实体(11)
- Add Two Numbers 链表基本应用
- Longest Substring Without Repeating Characters
- 【leetcode c++】ZigZag Conversion
- Codeforces Round #252 (Div. 2) B. Valera and Fruits(模拟)
- 总线设备驱动模型---platform篇
- java 两个相同元素的List,合并排序去除重复元素的快速算法
- HTML中id、name、class 区别
- const, static, extern,volatile 的使用
- php函数
- 程序员的量化交易之路(25)--Cointrader之MarketData市场数据实体(12)