My test cases will fail two popluar answers for this question.


  • 0
    D
    @Test
    public void test() {
    	RandomListNode head = new RandomListNode(0);
    	head.next = new RandomListNode(1);
    	head.random = new RandomListNode(5);
    
    	System.out.println(head.random.label);
    	
    	copyRandomList cr = new copyRandomList();
    	RandomListNode newHead = new RandomListNode(10);
    	newHead = cr.copyRandomList(head);
    	
    	assertEquals(newHead.label, 0);
    	assertEquals(newHead.random.label, 5);  ==> fail
    	assertNotNull(newHead.random);   ==> fail
    	assertNotNull(newHead.next); 
    	
    }
    

    This would fail as I noted below.

    For example, this popular answer cannot pass my test:

    https://leetcode.com/discuss/22421/solution-constant-space-complexity-linear-time-complexity


Log in to reply
 

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