Java solution got TLE but it was accepted 5 days ago.


  • 0
    C

    Hello As mentioned above, I noticed that my java solution which was accepted 5 days ago got TLE by a large data test case.

    Here is my solution

    public void connect(TreeLinkNode root) {
            while(root!=null && root.left!=null) {
                TreeLinkNode cur = root;
                while(cur!=null) {
                    if(cur.next!=null) {
                        cur.right.next = cur.next.left;
                    }
                    cur.left.next = cur.right;
                    cur = cur.next;
                }
                root = root.left;
            }
        } 
    

    I took reference from other answers. Anyone has idea to improve this?

    Thanks


Log in to reply
 

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