We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 782c0b8 commit b3c481aCopy full SHA for b3c481a
Linked List/deleteNodes.cpp
@@ -0,0 +1,21 @@
1
+class Solution {
2
+public:
3
+ ListNode* deleteNodes(ListNode* head, int m, int n) {
4
+ if(!head || !head->next) return head;
5
+ ListNode* temp = head;
6
+ while(temp && temp->next) {
7
+ int k = m-1;
8
+ while(k-- && temp) {
9
+ temp = temp->next;
10
+ }
11
+ ListNode* prev = temp;
12
+ int l = n+1;
13
+ while(l-- && temp) {
14
15
16
+ if(prev) prev->next = temp;
17
18
+
19
+ return head;
20
21
+};
0 commit comments