DEV Community

guang
guang

Posted on

leetcode 21

can't believe i used so clumsy way.i put dummy point to head as usual, then compare first value of list1 and list2, insert list2 node before or after list1 node. i also need consider the next node of list1. i doubt why it's so complicated for an easy problem but i didn't doubt about my solution! i also forgot to save node beforehand when swap node.
in the official solution, it's really simple and clean, didn't put dummy point to any node at first, then put it to smaller one of list1 and list2.
i also learned another recursive way.
i also learned an easy way to assign using or:

cur = list1 or list2

Top comments (0)