public int LengthOfLongestSubstring(string s) { int[] mOccur = new int[256]; int maxL = 0; char[] schar = s.ToCharArray(); for (int i = 0, j = 0; i < s.Length; ++i) { char ch = schar[i]; ++mOccur[ch]; while (mOccur[ch] > 1) { --mOccur[schar[j++]]; } maxL = Math.Max(maxL, i - j + 1); } return maxL; }