3 Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.
Example 1:
Input: "abcabcbb"
Output: 3
Explanation: The answer is "abc", with the length of 3.
Example 2:
Input: "bbbbb"
Output: 1
Explanation: The answer is "b", with the length of 1.
public int lengthOfLongestSubstring(String s) {
char a[]=s.toCharArray();
int result=0,flag=1;
for(int i=0;i<a.length;i++){
for(int j=0;j<i;j++){
if(a[i]==a[j])
flag=0;
}
if(flag==1){
result++;
}
flag=1;
}
return result;
}
网友评论