Longest Substring Without Repeating Characters --leetcode
来源:互联网 发布:建筑渲染软件 编辑:程序博客网 时间:2024/06/10 16:16
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.
接口函数:
int lengthOfLongestSubstring(char* s) {}我的函数:
int lengthOfLongestSubstring(char* s) { int x,i=0,j=1,k=0,count=0,ans=0; char f=0; x=strlen(s); if(x==1) //如果为单字符字串,直接返回字串长度1 return 1; if(x==0) //如果为空字符串,直接返回字串长度0 return 0; if(s[0]!=s[1]) //如果前两个字符不同则count从1开始计数 count=1; do{ //j不回头的往前爬行,每前进一步,则检测一次整个字串。// printf("&%d&\n",j); for(k=i;k<j;k++){ if(s[k]==s[j]){ //如果遇到重合字符,则尾部i跳转到j前面的重合字符的下一个位置。 f=1; count=j-k; //计算此时爬虫字串的长度。 i=++k;// printf("%d",count);// printf("[%c] ",s[k]); break; } } if(f!=1){ count++; //如果字串里面没有重合字符 } else f=0; //爬虫字串应遇到相同字符而被截断,被重新定义长度。 if(count>ans){ //选取最大串 ans=count;// printf("-%d-",count); } j++;// printf("\n"); }while(j!=x); return ans;}
0 0
- 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
- leetcode之Longest Substring Without Repeating Characters
- 解决DPDK脚本python执行时“OSError: [Errno 2] No such file or directory”的问题
- NumberPicker的显示样式设置
- Android 安装NDK
- 在ubuntu系统里给程序添加启动器
- TOken
- Longest Substring Without Repeating Characters --leetcode
- 布隆过滤器 (Bloom Filter) 详解
- HDU 1285 确定比赛名次(拓扑排序+略坑的条件)
- APP上架
- myeclipse Unsupported major.minor version 51.0解决办法
- GO类型嵌套
- eclipse show in windows explorer 在电脑 文件夹浏览此文件
- PHP网站开发实例教程之知识点归纳2(操作数据库)
- 一张图了解TCP/IP五层网络模型