Short Java


  • 0
    N
    public class Solution {
        public String findContestMatch(int n) {
            String[] arr = new String[n+1];
            for (int i = 1; i <= n; i++) {
                arr[i] = "" + i;
            }
            for (int i = 1; i <= n; i*=2) {
                for (int j = 1; j < n / i; j++) {
                    arr[j] = "(" + arr[j] + "," + arr[n/i+1-j] + ")";
                }
            }
            return arr[1];
        }
    }
    

Log in to reply
 

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