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> generateParenthesis(int n) { | |
| // Start typing your C/C++ solution below | |
| // DO NOT write int main() function | |
| vector<string> results ; | |
| if(n <= 0) return results; | |
| string s; |
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: | |
| struct comp{ | |
| bool operator()(ListNode* n1, ListNode* n2) { | |
| return n1->val > n2->val; | |
| } | |
| }; | |
| ListNode *mergeKLists(vector<ListNode *> &lists) { |
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 *swapPairs(ListNode *head) { | |
| if(head == NULL || head->next == NULL) return head; | |
| ListNode * newhead = head->next->next; | |
| ListNode * p = head->next; | |
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 *reverseList(ListNode *head) { | |
| if(head == NULL || head->next == NULL) return head; | |
| ListNode * pre = NULL; | |
| ListNode * current = head; | |
| ListNode * next = current->next; | |
| while(current) { | |
| next = current->next; | |
| current->next = pre; |
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 removeDuplicates(int A[], int n) { | |
| if(n <= 1) return n; | |
| int position = 1; | |
| for(int i = 1; i < n ; i++) { | |
| if(A[i] != A[i-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: | |
| int removeElement(int A[], int n, int elem) { | |
| int position = 0; | |
| for(int i = 0; i < n; i++) { | |
| if(A[i] != elem) { | |
| A[position++] = A[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: | |
| char *strStr(char *haystack, char *needle) { | |
| if(haystack == NULL || needle == NULL) return NULL; | |
| char * start = haystack; | |
| char * index1 = haystack; | |
| char * index2 = needle; |
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 divide(int dividend, int divisor) { | |
| int sign = 1; | |
| if(dividend < 0) sign *= -1; | |
| if(divisor < 0) sign *= -1; | |
| unsigned long long remain = abs((long long) dividend); | |
| unsigned long long factor = abs((long long) divisor); | |
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> findSubstring(string S, vector<string> &L) { | |
| int l = L.size(); | |
| vector<int> results; | |
| int s = S.length(); | |
| if( l == 0 || s == 0) return 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: | |
| void nextPermutation(vector<int> &num) { | |
| int size = num.size(); | |
| int left = -1; | |
| int right = 0; | |
| for(int i = 0; i < size - 1; i++) { |