LeetCode Swap Nodes in Pairs Explained - Java

LeetCode Swap Nodes in Pairs Explained - Java

Nick White

5 лет назад

38,655 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

sanaullah shareef
sanaullah shareef - 11.08.2023 16:18

If the given head contains odd number of nodes, this solution doesn't work

Ответить
Mack S
Mack S - 15.05.2023 00:24

Love the channel, but the explanation is lacking for this one!

Ответить
imran immu
imran immu - 21.10.2022 23:18

could u make another video
couldnt understand the code :(

Ответить
Sam C
Sam C - 08.04.2022 20:31

genius answer and clear explanation, thank you!

Ответить
Sumit Wadhwa
Sumit Wadhwa - 17.12.2021 16:23

The only thing missing in this video is your clap in the intro.

Ответить
Arun S P
Arun S P - 13.12.2021 09:01

Why is it in Medium? Sounds like Easy to me

Ответить
CarianSorceress
CarianSorceress - 17.09.2021 10:17

It is much better to draw some linkedlist for your explaination, I think that will be perfect. Anyway, thanks for sharing.

Ответить
Tejas Chauhan
Tejas Chauhan - 19.07.2021 21:22

Nick it would be better explanation with board

Ответить
one worldofstem
one worldofstem - 30.06.2021 18:23

Just wanna ask how do you come up with a temp ListNode method? Did you do some similar questions before? Thank you very much.

Ответить
sigma
sigma - 18.04.2021 19:44

why did u did first_node->next=second_node->next

Ответить
Raveena Mewani
Raveena Mewani - 13.10.2020 10:39

@Nick I really like your videos and I wanted to know have u solved all leetcode problems on Patreon?

Ответить
Kanishk Nagar
Kanishk Nagar - 28.09.2020 20:34

You look like Desmond from assassin's creed..xd awesome videos btw

Ответить
hardik
hardik - 05.09.2020 14:37

fck these algoexpert adds are so irritating

Ответить
DEEPAK GOYAL null (RA1711003010133)
DEEPAK GOYAL null (RA1711003010133) - 10.04.2020 15:13

why he has allocated memory to temp node.

Ответить
Aditya Firoda
Aditya Firoda - 22.02.2020 14:51

C++ Sol
ListNode* swapPairs(ListNode* head) {
ListNode* temp = new ListNode(0);
temp->next = head;
ListNode* curr = temp;

while(curr->next!= NULL && curr->next->next!= NULL)
{
ListNode* first = curr->next;
ListNode* second = curr->next->next;
first->next = second->next;
curr->next = second;
second->next = first;

curr = curr->next->next;
}


return temp->next;

Ответить
Mahalakshmi Thirumurthy
Mahalakshmi Thirumurthy - 13.01.2020 17:36

You are Smart, Nick :):)

Ответить
Vulfgang1
Vulfgang1 - 25.12.2019 00:11

There is an easier solution:


ListNode* swapPairs(ListNode* head) {
auto temp = head;
while(temp && temp->next)
{
std::swap(temp->val, temp->next->val);
temp = temp->next->next;
}
return head;
}

Ответить
FL Studio Tutorials
FL Studio Tutorials - 30.10.2019 02:00

You just got yourself a new subscriber.

Ответить
Mohor Narzary
Mohor Narzary - 16.07.2019 18:22

been searching this solution for Java. thanks! keep this channel running buddy.

Ответить
pooja guru
pooja guru - 13.06.2019 08:59

Great thinking!! :) I wanna develop my coding skills !! Would b great if I get some help :)

Ответить