首页 > 代码库 > 3 Longest Substring Without Repeating Characters
3 Longest Substring Without Repeating Characters
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。