[LeetCode]3. Longest Substring Without Repeating Characters
来源:互联网 发布:sdk软件开发工具包 编辑:程序博客网 时间:2024/04/29 23:43
题目:
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.
思路:
找最长子串,且子串内没有重复的字母,
比较简单。
class Solution {public:int lengthOfLongestSubstring(string s) {// Note: The Solution object is instantiated only once and is reused by each test case.bool a[256] = { false };for (int i = 0; i < 256; i++) a[i] = false;int temMax = 0,i=0,j;for ( j = 0; j < s.length(); j++) {if (!a[s[j]]) {a[s[j]] = true;}else {temMax=temMax > j - i ? temMax : j - i;while (s[i] != s[j]) {a[s[i]] = false;i++;}i++;}}temMax = temMax > s.length() - i ? temMax : s.length() - i;return temMax;}};
0 0
- [LeetCode]3.Longest Substring Without Repeating Characters
- LeetCode 3.Longest Substring Without Repeating Characters
- LeetCode --- 3. Longest Substring Without Repeating Characters
- [Leetcode] 3. Longest Substring Without Repeating Characters
- [leetcode] 3.Longest Substring Without Repeating Characters
- [leetcode] 3. Longest Substring Without Repeating Characters
- [Leetcode]3. Longest Substring Without Repeating Characters
- leetcode 3. Longest Substring Without Repeating Characters
- 【Leetcode】3. Longest Substring Without Repeating Characters
- leetcode 3. Longest Substring Without Repeating Characters
- LeetCode-3.Longest Substring Without Repeating Characters
- LeetCode 3.Longest Substring Without Repeating Characters
- LeetCode - 3.Longest Substring Without Repeating Characters
- Leetcode 3. Longest Substring Without Repeating Characters
- 3. Longest Substring Without Repeating Characters LeetCode
- (Leetcode)3. Longest Substring Without Repeating Characters
- leetcode 3. Longest Substring Without Repeating Characters
- LeetCode-3. Longest Substring Without Repeating Characters
- 160. Intersection of Two Linked Lists
- Mac / Linux Shell 批量重命名的方法总览-[转]
- unity3d之工程性能提升注意点
- CSS3颜色渐变模式总结
- 重构改善既有代码的设计
- [LeetCode]3. Longest Substring Without Repeating Characters
- jVM 常用参数
- MySQL 删除数据库中重复数据方法小结
- 分布式版本控制系统Git(三):git使用总结以及常用命令
- Android开发-AsyncTask
- 131. Palindrome Partitioning
- groovy入门3 集合
- Spring MVC 执行原理
- 深入浅出解析大数据平台架构