Can someone please explain why I have TLE?


  • 0
    R

    TLE

    if (!found) {
        order.add(0, stack.peek());
        visiting[stack.peek()] = false;
        stack.pop();
    }
    

    ACCEPTED

    if (!found) {
        int data = stack.peek();
        order.add(0, data);
        visiting[data] = false;
        stack.pop();
    }
    

    Both operations are essentially doing the same thing... and stack.peek() should be O(1) right? Then why one snippet out performed the other?


Log in to reply
 

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