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的更多相关文章

  1. LeetCode[3] Longest Substring Without Repeating Characters

    题目描述 Given a string, find the length of the longest substring without repeating characters. For exam ...

  2. [LeetCode] Longest Substring Without Repeating Characters 最长无重复子串

    Given a string, find the length of the longest substring without repeating characters. For example, ...

  3. 3. Longest Substring Without Repeating Characters(c++) 15ms

    Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...

  4. 【leetcode】Longest Substring Without Repeating Characters

    题目描述: Given a string, find the length of the longest substring without repeating characters. For exa ...

  5. Longest Substring Without Repeating Characters(C语言实现)

    Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...

  6. leetcode: longest substring without repeating characters

    July 16, 2015 Problem statement: Longest Substring Without Repeating Characters Read the blog: http: ...

  7. [LeetCode_3] Longest Substring Without Repeating Characters

    LeetCode: 3. Longest Substring Without Repeating Characters class Solution { public: int lengthOfLon ...

  8. Longest Substring Without Repeating Characters (c#)

    Given a string, find the length of the longest substring without repeating characters. For example, ...

  9. Longest Substring Without Repeating Characters(Difficulty: Medium)

    题目: Given a string, find the length of the longest substring without repeating characters. Examples: ...

随机推荐

  1. Lind.DDD.RedisClient~对StackExchange.Redis调用者的封装及多路复用技术

    回到目录 两雄争霸 使用StackExchange.Redis的原因是因为它开源,免费,而对于商业化的ServiceStack.Redis,它将一步步被前者取代,开源将是一种趋势,商业化也值得被我们尊 ...

  2. Euler-Maruyama discretization("欧拉-丸山"数值解法)

    欧拉法的来源 在数学和计算机科学中,欧拉方法(Euler method)命名自它的发明者莱昂哈德·欧拉,是一种一阶数值方法,用以对给定初值的常微分方程(即初值问题)求解.它是一种解决常微分方程数值积分 ...

  3. C语言学习 第八次作业总结

    本次作业其实没有新的内容,主要就是复习上一次的一维数组的相关内容.冯老师布置了5道题目,其中涉及到一些比较简单的排序或者是查找的方法.因为数据很少,所以直接使用for循环遍历就可以了. 关于本次作业, ...

  4. Socket通信类

    package com.imooc; import java.io.BufferedReader; import java.io.IOException; import java.io.InputSt ...

  5. jQuery 模态对话框示例

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. 【UOJ #35】后缀排序 后缀数组模板

    http://uoj.ac/problem/35 以前做后缀数组的题直接粘模板...现在重新写一下模板 注意用来基数排序的数组一定要开到N. #include<cstdio> #inclu ...

  7. vim编辑强制退出

    quit!命令可以进行强制退出 在修改文件时注意他的权限, ls -l:查看当前目录下的所有文件的详细信息

  8. consolel API大全-附测试结果

    f 简介: JS中默认没有console对象, 这是某些浏览器提供的浏览器内置对象, 低版本IE就没有, 其他主流浏览器应该都有.它能看到结构话的东西,如果是alert,淡出一个对象就是[object ...

  9. java 中正则表达式匹配

    String str = "#a#,#b#"; String reg="\\#+[^\\#]+\\#+"; Pattern p=Pattern.compile( ...

  10. a版本十日冲刺总汇

    DAY ONE: http://www.cnblogs.com/aruba/p/6041243.html 2016-11-08 DAY TWO: http://www.cnblogs.com/arub ...