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: ...
随机推荐
- polya/burnside 学习
参考链接: http://www.cnblogs.com/hankers/archive/2012/08/03/2622231.html http://blog.csdn.net/raalghul/a ...
- liunx关闭防火墙
Redirecting to /bin/systemctl stop iptables.service systemctl stop iptables.service ?????? centos从7开 ...
- Java学习笔记-抽象
开发软件的关键在于应用抽象的概念.方法抽象是通过将方法的使用和它的实现分离来实现的.方法的实现对用户隐藏在"黑匣子"中. 当编写一个大程序时,可以使用分治的策略,也成为逐步求精,将 ...
- 已知空间三个点,解算外接圆圆心坐标,C++编程实现
struct PT3 { double x, y, z; }; int solveCenterPointOfCircle(std::vector<PT3> pt, double cente ...
- Python 【第十一章】 Django模版
1.直接传值 urls.py """mysite URL Configuration The `urlpatterns` list routes URLs to view ...
- [LeetCode] Matchsticks to Square 火柴棍组成正方形
Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match ...
- php对应js math.random
<?php function random($min = 0, $max = 1) { return $min + mt_rand()/mt_getrandmax()*($max-$mi ...
- spring架构源码:
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px "Helvetica Neue"; color: #454545 } p. ...
- 解决SmartGit序列号问题
SmartGit过了30天试用期之后,就需要用户输入序列号才能继续使用,有一个办法可以跳过输入序列号. 一.windows+R 输入:%APPDATA%\syntevo\SmartGit 二.打开7 ...
- 【原】webp图片牛刀小试
其实今年很早就有接触到webp图片的概念,只是一直没怎么弄.今天在一个小项目中小用了一番.总结总结 采用 what,why,how的方式来总结 what? 什么是webp图片? 维基百科: ...