码迷,mamicode.com
首页 > 其他好文 > 详细

3 Longest Substring Without Repeating Characters

时间:2017-01-03 23:59:03      阅读:323      评论:0      收藏:0      [点我收藏+]

标签:longest   else   sts   ret   int   indexof   repeat   contain   public   

 1     public int lengthOfLongestSubstring(String s) {
 2         long length = s.length();
 3         String tmp = "";
 4         int substringLength = 0;
 5         for (int i = 0; i < length; i ++) {
 6             if (tmp.contains(("" + s.charAt(i)))) {
 7                 if (tmp.length() > substringLength)
 8                     substringLength = tmp.length();
 9                 int idx = tmp.indexOf(s.charAt(i) + "");
10                 tmp = tmp.substring(idx + 1) + s.charAt(i);
11             }
12             else {
13                 tmp = tmp + s.charAt(i);
14                 if (substringLength < tmp.length())
15                     substringLength = tmp.length();
16             }
17         }
18         return substringLength;
19     }

 

3 Longest Substring Without Repeating Characters

标签:longest   else   sts   ret   int   indexof   repeat   contain   public   

原文地址:http://www.cnblogs.com/cywhyy/p/6246688.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!