Комментарии:
If the given head contains odd number of nodes, this solution doesn't work
ОтветитьLove the channel, but the explanation is lacking for this one!
Ответитьcould u make another video
couldnt understand the code :(
genius answer and clear explanation, thank you!
ОтветитьThe only thing missing in this video is your clap in the intro.
ОтветитьWhy is it in Medium? Sounds like Easy to me
ОтветитьIt is much better to draw some linkedlist for your explaination, I think that will be perfect. Anyway, thanks for sharing.
ОтветитьNick it would be better explanation with board
ОтветитьJust wanna ask how do you come up with a temp ListNode method? Did you do some similar questions before? Thank you very much.
Ответитьwhy did u did first_node->next=second_node->next
Ответить@Nick I really like your videos and I wanted to know have u solved all leetcode problems on Patreon?
ОтветитьYou look like Desmond from assassin's creed..xd awesome videos btw
Ответитьfck these algoexpert adds are so irritating
Ответитьwhy he has allocated memory to temp node.
Ответить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;
You are Smart, Nick :):)
Ответить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;
}
You just got yourself a new subscriber.
Ответитьbeen searching this solution for Java. thanks! keep this channel running buddy.
ОтветитьGreat thinking!! :) I wanna develop my coding skills !! Would b great if I get some help :)
Ответить