Simple Java Solution


  • 0
    R
    public class Solution {
        public String findContestMatch(int n) {
            if(n == 0) return "";
            String[] matches = new String[n];
            for(int i = 1; i <= n; ++i)
                matches[i - 1] = String.valueOf(i);
            while(n >= 2) {
                String[] next = new String[n/2];
                int start = 0, end = matches.length - 1, i = 0;
                while(start < end) {
                    next[i] = "(" + matches[start] + "," + matches[end] + ")";
                    start++;
                    end--;
                    i++;
                }
                matches = next;
                n /= 2;
            }
            return matches[0];
        }
    }
    
    
    

Log in to reply
 

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