3. Longest Substring Without Repeating Characters
class Solution {
public int lengthOfLongestSubstring(String s) {
int arr[]=new int[122];
char c[]=s.toCharArray();
int m=0,m1=0;
for(int i=0;i<c.length;i++){
if(arr[c[i]]==0){
arr[c[i]]=1;
m++;
} else {
// m1=Math.max(m1,m);
Arrays.fill(arr,0);
m=0;i--;
}
m1=Math.max(m1,m);
}
return m1;
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter