public class Solution {

public int lengthOfLongestSubstring(String s) {

if(s.length() < 2) return s.length();

int[] value = new int[256];

for (int i = 0; i < 256; i++)

value[i] = -1;

//memset(value, -1, sizeof(value));

int last_start = 0;

int current_length = 0;

int max = 0;

char ch;

for(int i = 0; i < s.length(); i++)

{

ch = s.charAt(i);

if(value[ch] == -1)

{

current_length ++;

value[ch] = i;

}

else

{

if(last_start <= value[ch])

{

current_length = i - value[ch];

last_start = value[ch] + 1;

value[ch] = i;

}

else

current_length++;

}

if(current_length > max)

max = current_length;

}

return max;

}

}