Last active
October 25, 2020 20:17
-
-
Save kuang-da/ba3297a1fb4ca795aacceedd07674e7b to your computer and use it in GitHub Desktop.
[Notes about LeetCode] #leetcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include <stdlib.h> | |
include <stdio.h> | |
include <string> | |
include <string.h> | |
include <iostream> | |
include <algorithm> | |
include <vector> | |
include <unordered_map> | |
using namespace std; | |
class Solution { | |
public: | |
string findContestMatch(int n) { | |
vector<string> m(n); | |
for (int i = 0; i < n; i++) { | |
m[i] = to_string(i + 1); | |
} | |
while (n > 1) { | |
for (int i = 0; i < n / 2; i++) { | |
m[i] = "(" + m[i] + "," + m[n - 1 - i] + ")"; | |
} | |
n /= 2; | |
} | |
return m[0]; | |
} | |
}; | |
int main(int argc, char const *argv[]) | |
{ | |
Solution solution; | |
cout << solution.findContestMatch(8); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment