Longest Substring Without Repeating Characters
来源:互联网 发布:java工程师培训价格 编辑:程序博客网 时间:2024/06/08 02:01
问题
Given a string, find the length of the longest substring without repeating characters.
Examples:
Given “abcabcbb”, the answer is “abc”, which the length is 3.
Given “bbbbb”, the answer is “b”, with the length of 1.
Given “pwwkew”, the answer is “wke”, with the length of 3. Note that the answer must be a substring, “pwke” is a subsequence and not a substring.
解题思想
存在子串
若
代码
// 找到c在s[from, end]中的位置int find(char *s, int from, int end, char c) { int i; for (i = from; i <= end; ++i) { if (s[i] == c) { return i; } } return -1;}int lengthOfLongestSubstring(char* s) { int length_s = strlen(s); if (length_s < 2) { return length_s; } int longest = 1; int tmp_count = 1; int i, j; int k; for (i = 0, j = 1; j < length_s; ++j) { k = find(s, i, j - 1, s[j]); if (k == -1) { tmp_count++; continue; } else { if (tmp_count > longest) { longest = tmp_count; } i = k + 1; tmp_count = j - i + 1; } } if (tmp_count > longest) { longest = tmp_count; } return longest;}Characters
性能
阅读全文
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
- FasterRCNN画框小程序——VOC2007格式(python)
- 在dw的itemchanged事件里面,修改当前参数data
- MySQL索引
- 关于素数筛法的一点讨论
- 远程桌面无法复制文件解决方法
- Longest Substring Without Repeating Characters
- properties配置文件的使用
- 哈希表
- banner listview (无限轮播+ listview)
- Linux系统Oracle定时删除归档日志
- Source Insight基本使用和快捷键
- 守护进程以及fork两次的问题
- 二项堆与斐波那契堆
- ubuntu17.04插上网线没反应(设备未托管)