Content-Length: 295684 | pFad | http://github.com/JanaSabuj/Leetcode-solutions/commit/c7b7e6a9b17ca3bae0eee3f88b0403bf111fa4bb

ED Time: 20 ms (5.26%), Space: 10.8 MB (32.18%) - LeetHub · JanaSabuj/Leetcode-solutions@c7b7e6a · GitHub
Skip to content

Commit c7b7e6a

Browse files
committed
Time: 20 ms (5.26%), Space: 10.8 MB (32.18%) - LeetHub
1 parent b7989ce commit c7b7e6a

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

19-remove-nth-node-from-end-of-list/19-remove-nth-node-from-end-of-list.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ typedef struct ListNode node;
1212
class Solution {
1313
public:
1414
ListNode* removeNthFromEnd(ListNode* head, int n) {
15-
node* dummy = new node(0);
16-
dummy->next = head;
15+
node* dummy = new node(0);// create a tangible dummy node before head node -
16+
// helps in handle LL edge cases
17+
// dummy -> head -> ..... -> NULL
18+
dummy->next = head;
1719

18-
node* right = head;
19-
node* left = head;
20+
node* right = head, *left = head;
2021
node* prev = dummy;
2122

2223
// [-------------------------------]
@@ -32,6 +33,7 @@ class Solution {
3233

3334
while(right != NULL) {
3435
// right traverses (L-n) steps
36+
// along with it, head also traverses L-n steps
3537
right = right->next;
3638
prev = left;
3739
left = left->next;
@@ -41,4 +43,7 @@ class Solution {
4143

4244
return dummy->next;
4345
}
44-
};
46+
};
47+
48+
// node* x = a, y = b; XXX
49+
// it should be node* x = a, *y = b;

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/JanaSabuj/Leetcode-solutions/commit/c7b7e6a9b17ca3bae0eee3f88b0403bf111fa4bb

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy