Concise Java Solution, O(N) Time O(1) Space


  • 3
    O
    public class Solution {
        public ListNode reverseList(ListNode head) {
            ListNode pre = null;
            while(head != null) {
                ListNode next = head.next;
                head.next = pre;
                pre = head;
                head = next;
            }
            return pre;
        }
    }

Log in to reply
 

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