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

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Victoria
Victoria

Written by Victoria

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

No responses yet

Write a response