Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "ABCABCBB" are "abc", which the length is 3. For "bbbbb" the longest substring are "B", with the length of 1.
public class Solution {public int lengthoflongestsubstring (String s) { if (s.length () = = 0) return 0; String[] dp = new String[s.length ()];DP [0] = s.substring (0, 1); int index = 0;for (int i = 1; i < s.length (); i++) {if ( S.charat (i) = = S.charat (i-1)) dp[i] = s.substring (i-1, i); else {index = Dp[i-1].indexof (S.charat (i)); if (index = =-1) Dp[i] = dp[i-1] + s.charat (i); Elsedp[i] = dp[i-1].substring (index+1) +s.charat (i);}} index = 0;for (int i = 0; i < s.length (); i++) {if (Dp[i].length () > Index) index = Dp[i].length ();} return index;}}
(DP) 3.Longest Substring without repeating characters