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 trap(int A[], int n) { | |
| if(A == NULL || n <= 1) return 0; | |
| vector<int> left(n, 0); | |
| vector<int> right(n, 0); | |
| for(int i = 1; i <= n-1; i++) { | |
| left[i] = max(A[i-1], left[i-1]); | |
| right[n-i-1] = max(A[n-i], right[n-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
| class Solution { | |
| public: | |
| string multiply(string num1, string num2) { | |
| int len1 = num1.length(); | |
| int len2 = num2.length(); | |
| string s(len1+len2, '0'); | |
| for(int i = 0; i < len2; i++) { | |
| int carry = 0; | |
| for(int j = 0; j < len1; 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
| class Solution { | |
| public: | |
| bool isMatch(const char *s, const char *p) { | |
| const char* star = NULL; | |
| const char* olds = s; | |
| while (*s){ | |
| if ((*p=='?')||(*p==*s)){ | |
| s++; | |
| p++; |
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 jump(int A[], int n) { | |
| int step = 0; | |
| int target = n-1; | |
| while(target > 0) { | |
| for(int i = 0; i < target; 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
| class Solution { | |
| public: | |
| vector<vector<int> > permute(vector<int> &num) { | |
| int size = num.size(); | |
| vector<vector<int> > results; | |
| vector<int> entry; | |
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> > permuteUnique(vector<int> &num) { | |
| vector<vector<int> > results; | |
| int size = num.size(); | |
| if(size == 0) return results; | |
| vector<int> entry; |
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(); | |
| if(n == 0 || n == 1) return; | |
| //matrix[i][j] = matrix[n-1-j][i] | |
| int size = n%2==1? n/2+1:n/2; | |
| for(int i = 0; i < n/2; 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
| class Solution { | |
| public: | |
| long getCode(string s) { | |
| if(s.length() == 0) return 0; | |
| int code = 2166136261U; | |
| sort(s.begin(), s.end()); | |
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(x == 0 || x == 1) return x; | |
| if(x == -1) return n%2==1?-1:1; | |
| if(n == 0) return 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
| class Solution { | |
| public: | |
| vector<vector<string> > solveNQueens(int n) { | |
| vector<vector<string> > results; | |
| if(n == 0) return results; | |
| vector<int> entry; | |
| tryRow(0, n,entry, results); |