Output Contest Matches


  • 0

    Click here to see the full article post


  • 0
    R

    Hi @awice, I am unable to understand your lowest bit logic and in general, what is your algorithm intuition. Can you please provide a more detailed example and show the intuition.


  • 1
    N

    First solution should be O(n) space complexity.


  • 0
    S

    @njucs.cxgmail.com I agree with you. I think even the time complexity should be O(n).
    Time complexity = n + n/2 + n/4+ ... + 1 = 2n, so time complexity should be O(n).
    Space complexity = O(4n-3) = O(n)
    Here's my C++ code:

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

Log in to reply
 

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