From 602682b038f438357f1d07d897a0079f5795b8bf Mon Sep 17 00:00:00 2001 From: ishankaggarwal <36812796+ishankaggarwal@users.noreply.github.com> Date: Fri, 8 Apr 2022 15:09:15 -0700 Subject: [PATCH 1/3] Add files via upload --- cpp/23-Merge-K-Sorted-Lists.cpp | 51 +++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 cpp/23-Merge-K-Sorted-Lists.cpp diff --git a/cpp/23-Merge-K-Sorted-Lists.cpp b/cpp/23-Merge-K-Sorted-Lists.cpp new file mode 100644 index 000000000..7f61d8afa --- /dev/null +++ b/cpp/23-Merge-K-Sorted-Lists.cpp @@ -0,0 +1,51 @@ +/** + * Definition for singly-linked list. + * struct ListNode { + * int val; + * ListNode *next; + * ListNode() : val(0), next(nullptr) {} + * ListNode(int x) : val(x), next(nullptr) {} + * ListNode(int x, ListNode *next) : val(x), next(next) {} + * }; + */ + +class compare{ + public: + bool operator()(ListNode* a,ListNode* b){ + return a->val>b->val; + } +}; + +class Solution { +public: + ListNode* mergeKLists(vector& lists) { + + priority_queue,compare> pq; + + for(int i=0;inext=curr; + last=last->next; + + if(curr->next!=NULL){ + pq.push(curr->next); + } + } + return dummy->next; + } +}; \ No newline at end of file From 7bdf25b64ebb8e57e0428a8b7cbdbeaab50cd6ec Mon Sep 17 00:00:00 2001 From: ishankaggarwal <36812796+ishankaggarwal@users.noreply.github.com> Date: Fri, 8 Apr 2022 15:13:51 -0700 Subject: [PATCH 2/3] Add files via upload --- cpp/25-Reverse-Nodes-in-k-Group.cpp | 47 +++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 cpp/25-Reverse-Nodes-in-k-Group.cpp diff --git a/cpp/25-Reverse-Nodes-in-k-Group.cpp b/cpp/25-Reverse-Nodes-in-k-Group.cpp new file mode 100644 index 000000000..d7694611d --- /dev/null +++ b/cpp/25-Reverse-Nodes-in-k-Group.cpp @@ -0,0 +1,47 @@ +/** + * Definition for singly-linked list. + * struct ListNode { + * int val; + * ListNode *next; + * ListNode() : val(0), next(nullptr) {} + * ListNode(int x) : val(x), next(nullptr) {} + * ListNode(int x, ListNode *next) : val(x), next(next) {} + * }; + */ +class Solution { +public: + ListNode* reverseKGroup(ListNode* head, int k) { + + if(head==NULL || head->next==NULL){ + return head; + } + + ListNode* res=new ListNode(0); + res->next=head; + ListNode* start=res; + stack st; + ListNode* prev=NULL; + while(head!=NULL){ + ListNode* temp=head; + while(st.size()next; + } + if(st.size()==k){ + while(!st.empty()){ + prev=st.top(); + prev->next=NULL; + st.pop(); + start->next=prev; + start=start->next; + } + } + else{ + start->next=temp; + return res->next; + } + } + prev->next=NULL; + return res->next; + } +}; \ No newline at end of file From 4f68dcd1fa18896802e2eda859ecaf8a11b15717 Mon Sep 17 00:00:00 2001 From: ishankaggarwal Date: Fri, 8 Apr 2022 15:58:09 -0700 Subject: [PATCH 3/3] Added 30-Substring-with-Concatenation-of-All-Words.cpp --- ...string-with-Concatenation-of-All-Words.cpp | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 cpp/30-Substring-with-Concatenation-of-All-Words.cpp diff --git a/cpp/30-Substring-with-Concatenation-of-All-Words.cpp b/cpp/30-Substring-with-Concatenation-of-All-Words.cpp new file mode 100644 index 000000000..56940b581 --- /dev/null +++ b/cpp/30-Substring-with-Concatenation-of-All-Words.cpp @@ -0,0 +1,28 @@ +class Solution { +public: + vector findSubstring(string s, vector& words) { + + unordered_map mp; + for(string word:words){ + mp[word]++; + } + + int slen=s.size(); + int wlen=words.size(); + int len=words[0].size(); + + vector ans; + for(int i=0;i seen; + for(int j=0;j