本文共 777 字,大约阅读时间需要 2 分钟。
Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1.
Java代码:
public class Solution { public int lengthOfLongestSubstring(String s) { if(s.length()==0) return 0; if(s.length()==1) return 1; int length=0; String part=""+s.charAt(0); for(int i=1;ilength) { length=part.length(); } part=part.substring(index+1); i--; } } return part.length()>length?part.length():length; }}
转载地址:http://vnuni.baihongyu.com/