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 1000 | |
| #define MAX_INT 0x7fffffff | |
| int ans[MAXN][MAXN]; | |
| class Solution { | |
| public: | |
| int minPathSum(vector<vector<int> > &grid) { | |
| int n = grid.size(); | |
| int m = grid[0].size(); | |
| for (int i = 0; i < 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
| #define MAXN 100 | |
| int ans[MAXN][MAXN]; | |
| class Solution { | |
| public: | |
| int uniquePaths(int m, int n) { | |
| for (int i = 1; i <= m; ++i) | |
| for (int j = 1; j <= n; ++j) { | |
| if (i == 1 && j == 1) | |
| ans[i][j] = 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
| #define MAXN 100 | |
| int ans[MAXN][MAXN]; | |
| class Solution { | |
| public: | |
| int uniquePathsWithObstacles(vector<vector<int> > &obstacleGrid) { | |
| int n = obstacleGrid.size(); | |
| int m = obstacleGrid[0].size(); | |
| for (int i = 0; i < n; ++i) | |
| for (int j = 0; j < m; ++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
| /** | |
| * 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
| #define MAXN 10 | |
| int num[MAXN]; | |
| class Solution { | |
| public: | |
| string getPermutation(int n, int k) { | |
| for (int i = 0; i < n; ++i) | |
| num[i] = i + 1; | |
| while (--k) | |
| next_permutation(num, num + 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
| int dir[4][2] = {{0,1},{1,0},{0,-1},{-1,0}}; | |
| bool inBound(int x, int y, int n) { | |
| return x >= 0 && x < n && y >= 0 && y < n; | |
| } | |
| class Solution { | |
| public: | |
| vector<vector<int> > generateMatrix(int n) { | |
| vector<vector<int> > ans; |
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 lengthOfLastWord(const char *s) { | |
| int ans = 0; | |
| int cnt = 0; | |
| for (int i = 0; s[i] != 0; ++i) { | |
| if (s[i] == ' ') | |
| cnt = 0; | |
| else { | |
| cnt++; |
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 an interval. | |
| * struct Interval { | |
| * int start; | |
| * int end; | |
| * Interval() : start(0), end(0) {} | |
| * Interval(int s, int e) : start(s), end(e) {} | |
| * }; | |
| */ |
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 an interval. | |
| * struct Interval { | |
| * int start; | |
| * int end; | |
| * Interval() : start(0), end(0) {} | |
| * Interval(int s, int e) : start(s), end(e) {} | |
| * }; | |
| */ |
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 canJump(int A[], int n) { | |
| int dis = 0; | |
| for (int i = 0; i < n; ++i) { | |
| if (i <= dis) | |
| dis = max(dis, i + A[i]); | |
| else | |
| break; | |
| if (dis >= n - 1) |