You are viewing a single comment's thread. Return to all comments →
My C# solution without known of regexes:
static void Main(String[] args) { int len = Convert.ToInt32(Console.ReadLine()); string s = Console.ReadLine(); //my code int temp = 0; for (int i = 0; i < len; i++) { for (int j = i + 1; j < len; j++) { if (s[i] != s[j]) { bool gfn = true; Stack<char> sta = new Stack<char>(); foreach (char c in s) { if (c == s[i] || c == s[j]) { sta.Push(c); } } char[] ca = sta.ToArray(); for (int k = 0; k < ca.Length - 1; k++) { if (ca[k] != ca[k+1] && gfn == true) { gfn = true; } else { gfn = false; } } if (gfn == true && ca.Length > temp) { temp = ca.Length; } } } } Console.WriteLine(temp); }
Also the T(n) = O(n^3), it did work:)
Seems like cookies are disabled on this browser, please enable them to open this website
Two Characters
You are viewing a single comment's thread. Return to all comments →
My C# solution without known of regexes:
Also the T(n) = O(n^3), it did work:)