C++ short and simple solution. No need of recursion...


  • 0
    M
    string findContestMatch(int n) {
            vector<string> match;
            for(int i=0;i<n;i++) match.push_back(to_string(i+1));
            while(match.size()>1) {
                vector<string> temp;
                for(int i=0;i<match.size()/2;i++) {
                    string t="("+match[i]+","+match[match.size()-1-i]+")";
                    temp.push_back(t);
                }
                match=temp;
            }
            return match[0];
        }

Log in to reply
 

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