Share my java code


  • 0
    S
        public class Solution {
        public ListNode reverseList(ListNode head) {
            ListNode newOne = null;
            ListNode cur = null;
            while(head!=null){
                cur = newOne;
                newOne = new ListNode(head.val);;
                newOne.next = cur;
                head = head.next;
            }
            return newOne;
        }
    }

Log in to reply
 

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