Longest Substring Without Repeating Characters
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.
想了半天才想明白,这个题目啥意思。
就是说字符串中找一个没有一个字符是重复的最长的子字符串。比如说abcabcbb. 子字符串abc不重负,再加下一个a的话 就重复了。
下面这段代码 没有考虑效率问题
public static int lengthOfLongestSubstring(String s) {
int max = 0;
String temp = "";
char[] str = s.toCharArray();
for(int i = 0; i < str.length; i++)
{
if(temp.contains((str[i] + "").trim()))
{
temp = temp.substring(temp.indexOf(str[i]) + 1); 如果有重复的,就从重复的地方开始。
}
temp += str[i];
if(temp.length() > max)
{
max = temp.length();
}
}
return max;
}
Longest Substring Without Repeating Characters的更多相关文章
- LeetCode[3] Longest Substring Without Repeating Characters
题目描述 Given a string, find the length of the longest substring without repeating characters. For exam ...
- [LeetCode] Longest Substring Without Repeating Characters 最长无重复子串
Given a string, find the length of the longest substring without repeating characters. For example, ...
- 3. Longest Substring Without Repeating Characters(c++) 15ms
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- 【leetcode】Longest Substring Without Repeating Characters
题目描述: Given a string, find the length of the longest substring without repeating characters. For exa ...
- Longest Substring Without Repeating Characters(C语言实现)
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- leetcode: longest substring without repeating characters
July 16, 2015 Problem statement: Longest Substring Without Repeating Characters Read the blog: http: ...
- [LeetCode_3] Longest Substring Without Repeating Characters
LeetCode: 3. Longest Substring Without Repeating Characters class Solution { public: int lengthOfLon ...
- Longest Substring Without Repeating Characters (c#)
Given a string, find the length of the longest substring without repeating characters. For example, ...
- Longest Substring Without Repeating Characters(Difficulty: Medium)
题目: Given a string, find the length of the longest substring without repeating characters. Examples: ...
随机推荐
- phabricator-zh_CN汉化包
https://github.com/wanthings/phabricator-zh_CN 之前公司用这个做任务管理.可以将一些安排计划等指派给某个人跟进进度. 这个系统都是英文的,这是个缺憾.我找 ...
- [LeetCode] Shortest Word Distance II 最短单词距离之二
This is a follow up of Shortest Word Distance. The only difference is now you are given the list of ...
- 使用bat(批处理文件类型)两步更改笔记本IP
一.背景 在南农工的第三年里,学校终于给教学区覆盖了无线网NJAUPK,这解决了我在汇贤楼教室上自习没网写web的尴尬处境!经常在9栋和汇贤楼教学区之间来回,遇见了一个大问题:宿舍里无线需要更改IPV ...
- echarts-案例
关系图 http://echarts.baidu.com/echarts2/doc/example/force1.html http://www.cnblogs.com/spring_wang/p/4 ...
- BZOJ1303 [CQOI2009]中位数图
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...
- Linux哲学思想--基本法则
1.一切皆文件: 2.单一目的的小程序: 3.组合小程序完成复杂任务: 4.文本文件保存配置信息: 5.尽量避免捕获用户接口: 6.提供机制,而非策略. 自从Linux一诞生就注定了其成为经典的命运. ...
- project.pbxproj 的merge问题
基于xcode8.0 1.project.pbxproj 的结构 内部文件{archiveVersion=1 ; classes={};objectVersion=46;objects={};root ...
- 关于SQL的相关笔记【长期更新,只发一帖】
场景[1]多表联查时,主表与关联表同时与同一张(第三张表)有关联,类似三角恋关系- - 涉及表: HOUSE:记录了房屋信息 ROOMS:记录了房间信息 HOUSE_STATUS:记录了状态信息的中文 ...
- JS中class和id的区别
class和id的区别 class用于css的,id用于js的. 1)class页面上可以重复.id页面上唯一,不能重复. 2)一个标签可以有多个class,用空格隔开.但是id只能有id.
- CSS之表单元素
表单就是收集用户信息的,就是让用户填写的.选择的. 1 <div> 2 <h3>欢迎注册本网站&l ...