Skip to content

Commit

Permalink
Update insert-at-end.js
Browse files Browse the repository at this point in the history
  • Loading branch information
kounkou authored Nov 27, 2024
1 parent c1c56d0 commit fd1f6eb
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions logic/linked-list/insert-at-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@ var question = [
};
void insertAtEnd(ListNode** head, int v) {
ListNode* dummy = new ListNode();
dummy->val = v;
dummy->next = nullptr;
ListNode* dummy = new ListNode(v);
if (*head == nullptr) {
*head = dummy;
return;
}
ListNode* temp = *head;
while (temp->next != nullptr)
while (temp->next != nullptr) {
temp = temp->next;
}
temp->next = newNode;
temp->next = dummy;
}
void printList(ListNode* head) {
Expand Down

0 comments on commit fd1f6eb

Please sign in to comment.