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 INF 0x7fffffff | |
| int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; | |
| bool inBound(int x, int y, int n, int m) { | |
| return x >= 0 && x < n && y >= 0 && y < m; | |
| } | |
| 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 maxSubArray(int A[], int n) { | |
| if (n == 0) | |
| return 0; | |
| int ret = A[0]; | |
| int sum = 0; | |
| for (int i = 0; i < n; ++i) { | |
| sum += A[i]; | |
| ret = max(sum, ret); |
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: | |
| double pow(double x, int n) { | |
| if (n == 0) | |
| return 1; | |
| else if (n == 1) | |
| return x; | |
| if (n < 0) { | |
| x = 1 / x; | |
| n = -n; |
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<string> anagrams(vector<string> &strs) { | |
| vector<string> ans; | |
| map<string, int> M; | |
| for (int i = 0; i < strs.size(); ++i) { | |
| string tmp = strs[i]; | |
| sort(tmp.begin(), tmp.end()); | |
| try { | |
| M[tmp]++; |
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 rotate(vector<vector<int> > &matrix) { | |
| int n = matrix.size(); | |
| for (int leftx = 0; leftx < n / 2; leftx++) { | |
| int len = n - leftx * 2; | |
| int rightx = leftx + len - 1; | |
| for (int i = 0; i < len - 1; ++i) { | |
| int tmp = matrix[leftx][leftx + i]; | |
| matrix[leftx][leftx + i] = matrix[rightx - i][leftx]; |
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<vector<int> > permute(vector<int> &num) { | |
| vector< vector<int> > ans; | |
| ans.push_back(num); | |
| vector<int> id(num.size()); | |
| for (int i = 0; i < id.size(); ++i) | |
| id[i] = i; | |
| while (next_permutation(id.begin(), id.end())) { | |
| vector<int> tmp; |
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> | |
| class Solution { | |
| public: | |
| vector<vector<int> > permuteUnique(vector<int> &num) { | |
| int n = num.size(); | |
| vector<vector<int> > ans; | |
| vector<int> id(n); | |
| for (int i = 0; i < n; ++i) | |
| id[i] = i; |
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 <queue> | |
| struct Node { | |
| int pos; | |
| int val; | |
| Node(int p, int v) { | |
| pos = p; | |
| val = v; | |
| } | |
| }; |
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 500 | |
| int f[MAXN][MAXN]; | |
| bool isMatch_(const char* s, const char* p, int n, int m) { | |
| if (n < 0 && m < 0) | |
| return true; | |
| else if (n >= 0 && m < 0) | |
| return false; | |
| else if (n < 0) { | |
| for (int i = 0; i <= m; ++i) |
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 10000 | |
| int f[MAXN]; | |
| class Solution { | |
| public: | |
| string multiply(string num1, string num2) { | |
| int n = num1.length(); | |
| int m = num2.length(); | |
| memset(f, 0, sizeof(f)); | |
| for (int i = m - 1; i >= 0; --i) { |