转载:Longest Substring Without Repeating Characters
来源:互联网 发布:北京java程序员工资 编辑:程序博客网 时间:2024/06/05 21:08
leetcode 最大子串:
问题描述:
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语言实现:
#include <stdio.h>#include <stdlib.h>#include <string.h>int lengthOfLongestSubstring(char* s) { int i = 0, j = 0; int current = 0; int maxlength = 0; int start = 0; int map[128]; memset(map, 0, sizeof(map)); for ( i = 0; map[i]!='\0'; i++) { if (++map[s[i]] == 2) { if (maxlength < current) { maxlength = current; } for (j = start; j < i; j++) { if (s[j] == s[i]) { map[s[j]] = 1; start = j + 1; break; } else { current--; map[s[j]] = 0; } } } else { ++current; } } if (maxlength < current) { maxlength = current; } return maxlength;}
参考:
http://www.cnblogs.com/jiasheng/p/5623066.html
阅读全文
0 0
- 【转载】【leetcode】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
- #pragma data_seg 实现防止程序重复运行
- HDU 2037 区间相交问题系列之一
- Linux SCP 命令使用特定端口的注意事项
- java 大小写字母和数字的随机数
- Hibernate Annotation注解方式完成表映射OneToOne, OneToMany, ManyToMany
- 转载:Longest Substring Without Repeating Characters
- 破解was 密码oxr格式的网站
- swagger完整教程。杜绝copy
- vs头文件无法include的问题
- Three.js学习
- [LeetCode] 442. Find All Duplicates in an Array
- Emmet:一个Html/Css快速编辑神器的插件
- Spring(二)
- css html 如何将图片img标签 水平居中 垂直居中 和水平垂直居中,能自适应浏览器缩放。