My java solution


  • 0
    N
    public class Solution {
        public ListNode reverseList(ListNode head) {
            ListNode newList = null;
            ListNode curr = head;
            while(curr!=null){
                int currVal = curr.val;
                ListNode newNode = new ListNode(currVal);
                newList = add(newList,newNode);
                curr = curr.next;
                
            }
            return newList;
        }
        public ListNode add(ListNode newList,ListNode newNode){
            ListNode mergedList = new ListNode(newNode.val);
            mergedList.next = newList;
            return mergedList;
        }
        
    }

Log in to reply
 

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