Java solution @ 1ms


  • 0
    public class Solution {
        public ListNode reverseList(ListNode head) {
            if(head == null)return null;
            ListNode next_head = head.next;
            ListNode next = null;
            while(next_head != null){
                head.next = next;
                next = head;
                head = next_head;
                next_head = head.next;
            }
            head.next = next;
            return head;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.