My simple solution


  • 0
    Y
    public class Solution {
    public int lengthOfLongestSubstring(String s) {
        int array[]=new int[128];
        Arrays.fill(array,-1);
        int len=0;
        int start=-1;
        for(int i=0;i<s.length();i++)
        {
                start=start>=array[s.charAt(i)]?start:array[s.charAt(i)];
                len=(i-start)>len?(i-start):len;
                array[s.charAt(i)]=i;
        }
        return len;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.