Leetcode 24 Swap Nodes in Pairs

Victoria
Jun 15, 2021
my own solution

Again, the logic that head is not null and head.next is not null so that ans = head.next else return head can be shorten to if head is null or head.next is null then we return head. And then we continue with ans = head.next. this is again a logic problem that can be simplified.

other people’s solution

--

--

Victoria

"What if I fall?" "Oh my darling, but what if you fly?"