public int LengthOfLongestSubstring(string s) { Queue<char> queue=new Queue<char>(); int max=0; for(int i=0;i<s.Length;i++) { if(queue.Contains(s[i])) { max=Math.Max(max,queue.Count); while(queue.Dequeue()!=s[i]) { } //queue.Dequeue(); } queue.Enqueue(s[i]); } return Math.Max(max,queue.Count); }