O(n) in place Java Solution


  • 0
    Z
    public ListNode reverseList(ListNode head) {
      ListNode temp =null;
      ListNode previous =null;
      while (head !=null){
          temp=head.next;
          head.next=previous;
          previous=head;
          if (temp==null) return head;
          head=temp;
      }
      return head;
    }

  • 0
    K
    This post is deleted!

Log in to reply
 

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