LeetCode 3 LengthOfLongestSubstring

Given a string s, find the length of the longest substring without repeating characters.

        /*
         * Given a string s, find the length of the longest substring without repeating characters.
         * Input: s = "abcabcbb"
         * Output: 3
         * Explantion: the answer is "abc", with the length of 3.
         * Input: s = "pwwkew"
         * Output: 3
         * Explantion: the answer is "wke", with the length of 3.
         */

        public int LeetCode_3( string s)
        {
            int start = 0, end = 1, ans = 0, c = 0;
            string buf = "",s2 = "";

            for (int i = 0; i < s.Length; i++)
            {
                buf = s.Substring(start, end-start);

                if(end < s.Length)
                {
                    s2 = s.Substring(end, 1);
                    c = buf.IndexOf(s2);
                    if (c != -1)
                    {
                        start = start + (c+1);
                    }
                    end++;
                }

                if (ans < (end - start))
                {
                    ans = end - start;
                }


            }

            return ans;
        }