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
| C++: | |
| class Solution { | |
| public: | |
| bool exist(vector<vector<char>> &board, string word) { | |
| // Start typing your C/C++ solution below | |
| // DO NOT write int main() function | |
| if(word.length()==0) return false; | |
| int m=board.size(); | |
| if(m==0) return false; | |
| int n=board[0].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
| C++: | |
| class Solution { | |
| public: | |
| void sortColors(int A[], int n) { | |
| // Start typing your C/C++ solution below | |
| // DO NOT write int main() function | |
| int head=0; | |
| int tail=n-1; | |
| int cur=0; | |
| while(cur<=tail){ |
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
| C++: | |
| class Solution { | |
| public: | |
| string minWindow(string S, string T) { | |
| // Start typing your C/C++ solution below | |
| // DO NOT write int main() function | |
| if(T.length()==0||S.length()<T.length()) return ""; | |
| int sLen=S.length(); | |
| int tLen=T.length(); | |
| int ct1[256]; |
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
| C++: | |
| class Solution { | |
| public: | |
| bool searchMatrix(vector<vector<int> > &matrix, int target) { | |
| // Start typing your C/C++ solution below | |
| // DO NOT write int main() function | |
| if(matrix.size()==0) return false; | |
| int rowLow=0; | |
| int rowHigh=matrix.size()-1; | |
| int rowMiddle=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
| C++: | |
| class Solution { | |
| public: | |
| void setZeroes(vector<vector<int> > &matrix) { | |
| // Start typing your C/C++ solution below | |
| // DO NOT write int main() function | |
| bool row=false; | |
| bool col=false; | |
| for(int i=0;i<matrix.size();i++) | |
| if(matrix[i][0]==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
| C++: | |
| class Solution { | |
| public: | |
| int minDistance(string word1, string word2) { | |
| // Start typing your C/C++ solution below | |
| // DO NOT write int main() function | |
| int d[word1.length()+1][word2.length()+1]; | |
| d[0][0]=0; | |
| for(int i=1;i<=word1.length();i++) d[i][0]=i; | |
| for(int j=1;j<=word2.length();j++) d[0][j]=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
| C++: | |
| class Solution { | |
| public: | |
| string simplifyPath(string path) { | |
| // Start typing your C/C++ solution below | |
| // DO NOT write int main() function | |
| stack<string> result; | |
| string cur; | |
| for(int i=0;i<path.length();i++){ | |
| if(path[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
| C++: | |
| class Solution { | |
| public: | |
| int climbStairs(int n) { | |
| // Start typing your C/C++ solution below | |
| // DO NOT write int main() function | |
| if(n==0) return 0; | |
| if(n==1) return 1; | |
| int one=1; | |
| int two=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
| (1)二分法 | |
| C++: | |
| class Solution { | |
| public: | |
| int sqrt(int x) { | |
| // Start typing your C/C++ solution below | |
| // DO NOT write int main() function | |
| if(x<0) return -1; | |
| long long x1=(long long)x; | |
| long long left=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
| C++: | |
| class Solution { | |
| public: | |
| vector<int> plusOne(vector<int> &digits) { | |
| // Start typing your C/C++ solution below | |
| // DO NOT write int main() function | |
| vector<int> result; | |
| stack<int> sum; | |
| int plusNumber=1; | |
| for(int i=digits.size()-1;i>=0;i--){ |