C# O(n)


  • 0
    H
    public string FindContestMatch(int n) {
            List<string> list = new List<string>();
            for(int i = 1; i <= n; i++) list.Add(i.ToString());
            
            while(list.Count > 1) {
                List<string> newList = new List<string>();
                n = list.Count;
                for(int i = 0; i < n / 2; i++) {
                    newList.Add(string.Format("({0},{1})", list[i], list[n - i - 1]));
                }
                
                list = newList;
            }
            
            return list[0];
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.