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 longestValidParentheses(string s) { | |
| int len = s.length(); | |
| if(len < 2) return 0; | |
| stack<int> myStack; | |
| int totalMax = 0; | |
| int start = 0; | |
| for(int i = 0; i < len; 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: | |
| int search(int A[], int n, int target) { | |
| if(n <= 0 || A == NULL) return -1; | |
| int start = 0; | |
| int end = n - 1 ; | |
| while(start <= 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: | |
| vector<int> searchRange(int A[], int n, int target) { | |
| vector<int> results(2,0); | |
| results[0] = searchRangeHelper(A, n, target, true); | |
| results[1] = searchRangeHelper(A, n, target, false); | |
| return results; | |
| } | |
| int searchRangeHelper(int A[], int n, int target, bool left) { |
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 searchInsert(int A[], int n, int target) { | |
| int start = 0; | |
| int end = n - 1; | |
| while(start <= end) { | |
| int mid = start + (end - start)/2; | |
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 isValidSudoku(vector<vector<char> > &board) { | |
| for(int i = 0; i < 9; i++) { | |
| if(!verifyRowCol(board, i) || !verifyblock(board, 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: | |
| void solveSudoku(vector<vector<char> > &board) { | |
| solveSudokuHelper(board); | |
| } | |
| bool solveSudokuHelper(vector<vector<char> > & board) { | |
| for(int i = 0; i < 9; 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 intToString(int n){ | |
| stringstream ss; | |
| ss << n; | |
| return ss.str(); | |
| } | |
| string countAndSay(int n) { | |
| string current = "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<int> > combinationSum(vector<int> &candidates, int target) { | |
| vector<vector<int> > results; | |
| vector<int> entry; | |
| sort(candidates.begin(), candidates.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: | |
| vector<vector<int> > combinationSum2(vector<int> &num, int target) { | |
| vector<vector<int> > results; | |
| vector<int> entry; | |
| if(num.size() <= 0) return results; | |
| sort(num.begin(), num.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: | |
| void swap(int & a, int & b) { | |
| int temp = a; | |
| a = b; | |
| b = temp; | |
| } | |
| int firstMissingPositive(int A[], int n) { | |