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

  • 0
    public void test() {
    	RandomListNode head = new RandomListNode(0); = new RandomListNode(1);
    	head.random = new RandomListNode(5);
    	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

    This would fail as I noted below.

    For example, this popular answer cannot pass my test:

Log in to reply

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