Skip to content

Instantly share code, notes, and snippets.

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;
class Solution {
public:
struct comp{
bool operator()(ListNode* n1, ListNode* n2) {
return n1->val > n2->val;
}
};
ListNode *mergeKLists(vector<ListNode *> &lists) {
class Solution {
public:
ListNode *swapPairs(ListNode *head) {
if(head == NULL || head->next == NULL) return head;
ListNode * newhead = head->next->next;
ListNode * p = head->next;
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;
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]) {
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];
}
}
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;
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);
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;
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++) {