c++ deque solution


  • 0
    T
    class Solution {
    public:
        
        string findContestMatch(int n) {
            deque<string> q;
            for (int i = 1; i <= n; ++i) {
                q.push_back(to_string(i));
            }
            while (q.size() != 1) {
                deque<string> tq;
                while (!q.empty()) {
                    string s = "(" + q.front() + "," + q.back() + ")";
                    q.pop_front(); q.pop_back();
                    tq.push_back(s);
                }
                q = tq;
            }
            return q.front();
        }
    };
    

Log in to reply
 

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