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 isValid(int row, int col, vector<int> path) { | |
| for(int i = 0; i < path.size(); i++) { | |
| if( col == path[i] || abs(row - i) == abs(col -path[i])) | |
| return false; | |
| } | |
| return true; | |
| } |
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) { | |
| int maxTotal = A[0]; | |
| int maxSofar = A[0]; | |
| for(int i = 1; i < n; i++) { | |
| maxSofar = max(A[i], maxSofar + A[i]); | |
| maxTotal = max(maxSofar, maxTotal); |
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> spiralOrder(vector<vector<int> > &matrix) { | |
| vector<int> results; | |
| int row = matrix.size(); | |
| if(row == 0) return results; | |
| int col = matrix[0].size(); | |
| for(int i =0; i <= row/2 && i<= col/2; i++) | |
| spiralOrderHelper(matrix, i, results); |
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 canReach = A[0]; | |
| if(n == 1) return true; | |
| for(int i = 1; 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
| bool hasOverlap(Interval a, Interval b) { | |
| return !((a.start > b.end) ||(a.end < b.start)); | |
| } | |
| void mergeTwo(Interval & a, Interval b) { | |
| a.start = min(a.start, b.start); | |
| a.end = max(a.end, b.end); | |
| } | |
| bool isLess(const Interval a, const Interval 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: | |
| vector<Interval> insert(vector<Interval> &intervals, Interval newInterval) { | |
| vector<Interval> results; | |
| Interval current; | |
| for(int i = 0; i < intervals.size(); i++) { | |
| current = intervals[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: | |
| bool isalpha(const char c) { | |
| return c>='a' && c<= 'z' || c>='A' && c<='Z'; | |
| } | |
| int lengthOfLastWord(const char *s) { | |
| int len = strlen(s); | |
| if(len == 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: | |
| vector<vector<int> > generateMatrix(int n) { | |
| vector<vector<int> > results(n, vector<int>(n,0)); | |
| int start = 1; | |
| for(int i = 0; i <= n/2; i++) { | |
| int startx = i; | |
| int starty = i; | |
| int endx = n-1-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 getPermutation(int n, int k) { | |
| if(n == 1) return string("1"); | |
| vector<int> num(n,0); | |
| int factor = 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: | |
| ListNode *rotateRight(ListNode *head, int k) { | |
| if(head == NULL || k == 0) return head; | |
| ListNode * p = head; | |
| int len = 1; | |
| while(p->next) { | |
| len++; |