C++ 7 lines easy understand brute force


  • 0
    B
    class Solution {
    public:
        string findContestMatch(int n) {
            vector<string>ans;
            for(int i = 1; i <= n; i++) ans.push_back(to_string(i));
            while(ans.size() > 1)
            {
                vector<string>temp;
                for(int i = 0; i < ans.size()/2; i++)
                    temp.push_back(string("(") + ans[i] + ","+ans[ans.size()-1-i]+")");
                ans = temp;
            }
            return ans[0];
        }
    };

Log in to reply
 

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