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 <algorithm> | |
| using namespace std; | |
| /** | |
| * Definition for binary tree | |
| * struct TreeNode { | |
| * int val; | |
| * TreeNode *left; | |
| * TreeNode *right; | |
| * TreeNode(int x) : val(x), left(NULL), right(NULL) {} |
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 <algorithm> | |
| using namespace std; | |
| /** | |
| * Definition for binary tree | |
| * struct TreeNode { | |
| * int val; | |
| * TreeNode *left; | |
| * TreeNode *right; | |
| * TreeNode(int x) : val(x), left(NULL), right(NULL) {} |
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
| class Solution { | |
| public: | |
| int climbStairs(int n) { | |
| int f[3] = {1, 0, 0}; | |
| int cur = 0; | |
| for (int i = 1; i <= n; ++i) { | |
| cur = i % 3; | |
| f[cur] = f[0] + f[1] + f[2] - f[cur]; | |
| } | |
| return f[cur]; |
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 <algorithm> | |
| using namespace std; | |
| class Solution { | |
| public: | |
| void dfs(vector<vector<int> >& ret, vector<int>& tmp, vector<int>& cands, int left, int target) { | |
| if (target == 0) { | |
| ret.push_back(tmp); | |
| return; | |
| } |
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 <algorithm> | |
| using namespace std; | |
| class Solution { | |
| public: | |
| void dfs(vector<vector<int> >& ret, vector<int>& tmp, vector<int>& cands, int left, int target) { | |
| if (target == 0) { | |
| ret.push_back(tmp); | |
| return; | |
| } |
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
| class Solution { | |
| public: | |
| void dfs(vector<vector<int> >& ret, vector<int>& tmp, int n, int left, int k) { | |
| if (k == 0) { | |
| ret.push_back(tmp); | |
| return; | |
| } | |
| for (int i = left; i <= n; ++i) { | |
| tmp.push_back(i); | |
| dfs(ret, tmp, n, i + 1, k - 1); |
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 <tr1::unordered_map> | |
| using namespace std; | |
| /** | |
| * Definition for binary tree | |
| * struct TreeNode { | |
| * int val; | |
| * TreeNode *left; | |
| * TreeNode *right; | |
| * TreeNode(int x) : val(x), left(NULL), right(NULL) {} |
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 <tr1::unordered_map> | |
| using namespace std; | |
| /** | |
| * Definition for binary tree | |
| * struct TreeNode { | |
| * int val; | |
| * TreeNode *left; | |
| * TreeNode *right; | |
| * TreeNode(int x) : val(x), left(NULL), right(NULL) {} |
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
| #!/usr/bin/python | |
| def remove(buf): | |
| dict = {} | |
| wordslist = [] | |
| for line in buf: | |
| words = line.split() | |
| wordslist.append(words) | |
| for i in xrange( len(words) - 2 ): | |
| phrase = ' '.join(words[i:i+3]) |
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
| #!/usr/bin/python | |
| def dfs(buf, flag, nodes, start, cur): | |
| if flag[cur]: | |
| if cur == start and len(nodes) != 2 and min(nodes) == start: | |
| return len(nodes) | |
| else: | |
| return -1 | |
| flag[cur] = True | |
| nodes.append(cur) |