Accepted Solution


  • 1
    D

    public class Solution {

    public boolean isSameTree(TreeNode p, TreeNode q) {
     if( p == null && q == null) {
         return true;
     }
     if(p == null || q == null) {
         return false;
     }
     if( p.val == q.val) {
        return isSameTree(p.left,q.left) && isSameTree(p.right, q.right);
    }
    return false;
    

    }
    }


  • 0
    A

    Nice solution! :)

    I had a JavaScript solution: https://discuss.leetcode.com/topic/121171/javascript-solution

    I like yours better. I converted to JavaScript, and as expected, it worked beautifully.

    Mine ran at 128ms and using your solution in JS 96ms – a 33% increase!


Log in to reply
 

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