Another bug in leetcode's JS runtime env

For problem 138. Copy List with Random Pointer, if I use the JS code below, there will be an error. The error is not caused by the code I added.

code:

var copyRandomList = function(head) {
    var mp = new Map()
    var tp = head
    while(tp) {
        var cur = new Node(tp.val)
        mp.set(tp,cur)
        tp=tp.next
    }
    tp = head
    while(tp) {
        if(tp.next) {
            var copy = mp.get(tp)
            var nxt = tp.next
            var copynext = mp[nxt]
            copy.next = copynext           
        }
        if(tp.random) {
            var curRandom = tp.random
            var newRandom = mp.get(curRandom)
            copy.random = newRandom
        }
        tp = tp.next
    }
    return mp.get(head)
};

If you run, there is a runtime error which is from line81. This code doesn't have line81.

Comments (0)