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
| /** | |
| * Definition for binary tree | |
| * struct TreeNode { | |
| * int val; | |
| * TreeNode *left; | |
| * TreeNode *right; | |
| * TreeNode(int x) : val(x), left(NULL), right(NULL) {} | |
| * }; | |
| */ | |
| class Solution { |
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<string>& ret, char* buf, int n, int id, int cnt1, int cnt2) { | |
| if (id == 2 * n) { | |
| buf[id] = 0; | |
| ret.push_back(buf); | |
| return; | |
| } | |
| if (cnt1 < n) { | |
| buf[id] = '('; |
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: | |
| vector<int> grayCode(int n) { | |
| vector<int> ret; | |
| if (n == 0) { | |
| ret.push_back(0); | |
| return ret; | |
| } | |
| else if (n == 1) { | |
| ret.push_back(0); |
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: | |
| char *strStr(char *haystack, char *needle) { | |
| if (*haystack == NULL && *needle == NULL) | |
| return haystack; | |
| char* ret; | |
| for (ret = haystack; *ret != NULL; ++ret) { | |
| int k; | |
| for (k = 0; needle[k] != NULL; ++k) | |
| if (ret[k] != needle[k]) |
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 merge(int A[], int m, int B[], int n) { | |
| int *C = new int[m]; | |
| memcpy(C, A, m * sizeof(int)); | |
| int i = 0, j = 0; | |
| int id = 0; | |
| while (i < m || j < n) { | |
| if (i == m) | |
| A[id++] = B[j++]; |
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
| #define MAXN 100 | |
| int f[MAXN][MAXN][MAXN]; | |
| class Solution { | |
| public: | |
| bool dp(int f[MAXN][MAXN][MAXN], const string& s1, const string& s2, int i, int j, int k) { | |
| if (f[i][j][k] != -1) | |
| return f[i][j][k] == 1; | |
| if (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
| /** | |
| * Definition for singly-linked list. | |
| * struct ListNode { | |
| * int val; | |
| * ListNode *next; | |
| * ListNode(int x) : val(x), next(NULL) {} | |
| * }; | |
| */ | |
| class Solution { | |
| public: |
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 maximalRectangle(vector<vector<char> > &matrix) { | |
| int n = matrix.size(); | |
| if (0 == n) | |
| return 0; | |
| int m = matrix[0].size(); | |
| if (0 == m) | |
| return 0; | |
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
| #define MAXN 1000000 | |
| int st[MAXN]; | |
| int l[MAXN]; | |
| int r[MAXN]; | |
| class Solution { | |
| public: | |
| int largestRectangleArea(vector<int> &height) { | |
| int n = height.size(); |
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
| /** | |
| * Definition for singly-linked list. | |
| * struct ListNode { | |
| * int val; | |
| * ListNode *next; | |
| * ListNode(int x) : val(x), next(NULL) {} | |
| * }; | |
| */ | |
| class Solution { | |
| public: |