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 uniquePaths(int m, int n) { | |
| if(m <= 0 || n <= 0) return 0; | |
| if(m == 1 || n == 1) return 1; | |
| vector<vector<int> > result(m, vector<int>(n, 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: | |
| int uniquePaths(int m, int n) { | |
| //if(m == 1 || n == 1) return 1; //no need to take care of this case; | |
| vector<int> result(n, 1); | |
| for(int i = m-2; i >= 0; i--) { | |
| for(int j = n - 2; j >= 0; 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: | |
| int uniquePathsWithObstacles(vector<vector<int> > &obstacleGrid) { | |
| int row = obstacleGrid.size(); | |
| if(row == 0) return 0; | |
| int col = obstacleGrid[0].size(); | |
| if(col == 0) 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
| class Solution { | |
| public: | |
| int minPathSum(vector<vector<int> > &grid) { | |
| int row = grid.size(); | |
| if(row == 0) return 0; | |
| int col = grid[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
| class Solution { | |
| public: | |
| ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) { | |
| if(l1 == NULL) return l2; | |
| if(l2 == NULL) return l1; | |
| ListNode * head; | |
| ListNode * l3; | |
| ListNode * l4; |
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 swap(string &a, string &b) { | |
| string temp = a; | |
| a = b; | |
| b = temp; | |
| } | |
| string addBinary(string a, string b) { | |
| if(a.length() < b.length()) swap(a, b); |
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 isDigit(const char c) { | |
| return c >= '0' && c <= '9'; | |
| } | |
| bool isNumber(const char *s) { | |
| if(s == NULL) return false; | |
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> plusOne(vector<int> &digits) { | |
| int size = digits.size(); | |
| if(size == 0) return digits; | |
| int i = size - 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<string> fullJustify(vector<string> &words, int L) { | |
| int size = words.size(); | |
| vector<string> results; | |
| if(L == 0 || size == 0) { results.push_back(""); return results; } | |
| int start = 0; | |
| int end = 0; | |
| int len = 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: | |
| int sqrt(int x) { | |
| int start = 0; | |
| int end = x/2+1; | |
| if(x == 0 || x == 1) return x; | |
| while(start <= end) { // = is very important, bug here! | |
| int mid = start + (end - start)/2; |