最长的无重复字符的字符串 longest substring with no repeating characters
来源:互联网 发布:信捷plc编程案例 编辑:程序博客网 时间:2024/06/11 13:31
相关问题:[LeetCode] minimum window 包含所有字符的最小子字符串
Given a string, find the length of the longest substring without repeating characters. For example,the longest substrings without repeating characters for “ABDEFGABEF” are “BDEFGA” and “DEFGAB”, with length 6. For “BBBB” the longest substring is “B”, with length 1. For “GEEKSFORGEEKS”, there are two longest substrings shown in the below diagrams, with length 7.
The desired time complexity is O(n) where n is the length of the string.
自己的算法如下,思路可以参考http://www.geeksforgeeks.org/length-of-the-longest-substring-without-repeating-characters/:
#include<iostream>#include<stdio.h>#include<stdlib.h>using namespace std;#include <string.h>#include <set>int main (){ set<char> str_set; char * str = "ABDEFGABEFFFFFFFFFFFF"; str_set.insert(*str); int n = strlen(str); int i=0, j=1; int max_ = 0; while(1) { for(; j<n; j++) { if(str_set.find(*(str+j) )!=str_set.end()) break; str_set.insert(*(str+j)); max_ = max(max_, (int) str_set.size() ); } if(j==n-1) break; for(; i<n; i++) { str_set.erase( *(str+i) ); if( *(str+j) == *(str+i) ) { i++; break; } } } cout<<max_<<endl;}
0 0
- 最长的无重复字符的字符串 longest substring with no repeating characters
- 3. Longest Substring Without Repeating Characters 无重复字符的最长子字符串
- leetcode:Longest Substring Without Repeating Characters (寻找最长无重复字符的子串)
- Longest Substring Without Repeating Characters (返回最长无字符重复的子串长度)
- Longest Substring Without Repeating Characters (最长无重复字符的子串)
- [Leetcode #3]Longest Substring Without Repeating Characters 无重复字符的最长子串
- [Lintcode] Longest Substring Without Repeating Characters 最长无重复字符的子串
- 384.Longest Substring Without Repeating Characters-最长无重复字符的子串(中等题)
- 字符的最长无重复子串长度Longest Substring Without Repeating Characters
- LeetCode-3:Longest Substring Without Repeating Characters (最长无重复字符的子串) --medium
- Longest Substring Without Repeating Characters 字符串中最长的无重复子串长度
- Leet Code 3. Longest Substring Without Repeating Characters (最长的没有重复字符的子字符串)
- 没有重复字符的最长子字符串(Longest Substring Without Repeating Characters)
- LeetCode 题解 3. Longest Substring Without Repeating Characters(最长不含重复字符的子字符串)
- Longest Substring Without Repeating Characters(最长的无重复的字串)
- LeetCode OJ 之 Longest Substring Without Repeating Characters (无重复的最长子串)
- Longest Substring Without Repeating Characters 最长不重复字符的字串 @LeetCode
- Longest Substring Without Repeating Characters 不含重复字符的最长子串
- 树莓派平台4位共阴数码管Python编程
- 使用skyeye运行uboot, linux-2.6.31和busybox
- 向左对齐的Gallery
- quicksort--python--others
- java 集合总览
- 最长的无重复字符的字符串 longest substring with no repeating characters
- Hadoop即将过时了吗?
- Unity MeshBaker 合并网格和材质
- When Linux Runs Out of Memory
- Java webp转jpg
- 第13周项目--数组大折腾3
- restful基于SpringMVC的实现(上)
- nupt-acm1008
- Linux进程创建,子进程对父进程资源“写时拷贝”的证明