Simple 5 Line Recursive Solution (Java)


  • 0
    C
    public class Solution {
        public RandomListNode copyRandomList(RandomListNode head) {
            
                if (head == null) {return null;}
            
                RandomListNode temp = new RandomListNode(head.label);
                temp.random = head.random == null ? null : new RandomListNode(head.random.label);
                temp.next = copyRandomList(head.next);
            
                return temp;
        }
    }
    

Log in to reply
 

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