
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.
