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: ...
随机推荐
- Oracle 获取当前日期及日期格式
http://blog.sina.com.cn/s/blog_6168ee920100l2ye.html Oracle 获取当前日期及日期格式 获取系统日期: SYSDATE() 格式化日期: ...
- HTML 学习笔记 JavaScript(call方法详解)
http://www.cnblogs.com/f-dream/p/4950918.html
- Linux下yum安装MySQL
写这篇文章的原因是:在刚开始使用Linux操作系统时想要搭建LAMP环境,于是开始在Google和百度上各种寻找资料,碰到了不是很多的问题后,我决定写这篇文章总结一下在Linux下yum安装MySQL ...
- 当AngularJS POST方法碰上PHP
问题描述 怎么POST过去给PHP都收不到资料? $_POST方法取不到正确的传入值! 原理说明 AngularJS这套framework使用的AJAX方法中,资料传递的格式为JSON,送出去的hea ...
- Firefox默认英文修改中文
对于firefox,中文还是看着顺眼,为了自己的顺心.动起手来,自力更生,丰衣足食! 01.确定Linux的firefox版本 firefox -v 02.下载对应版本的中文语言包 http://ft ...
- IO流-----写到输出流
输出流:---链接:http://blog.csdn.net/du_minchao/article/details/49045421 /** * 方法名:writeStream * 方法描述:写到输出 ...
- localStorage使用总结
一.什么是localStorage.sessionStorage 在HTML5中,新加入了一个localStorage特性,这个特性主要是用来作为本地存储来使用的,解决了cookie存储空间不足的问题 ...
- Puzzle 面向服务/切面(AOP/IOC)开发框架 For .Net
Puzzle 面向服务/切面AOP开发框架 For .Net AOP主要实现的目的是针对业务处理过程中的切面进行提取,它所面对的是处理过程中的某个步骤或阶段,以获得逻辑过程中各部分之间低耦合性的隔离效 ...
- Code Conventions for the Java
Oracel官方JAVA编码规范指引 http://www.oracle.com/technetwork/java/codeconvtoc-136057.html
- java面向对象---对象初始化
在本地变量中,如果定义了一个变量后没有赋值就使用,那么eclipse就会报错:但是在成员变量中,java是会强制给一个没有初始化的变量一个默认的初始值0, 如果是一个boolean类型的变量,那么默认 ...