keep learning, keep coding!
Problem - Same Tree
Given the roots of two binary trees p and q, write a function to check if they are the same or not.
Two binary trees are considered the same if they are structurally identical, and the nodes have the same value.
翻譯蒟蒻
比較兩個二元樹是否相同。也就是需要比較他們的結構和每個對應節點的值是否相等。
Example 1:
1
2Input: p = [1,2,3], q = [1,2,3]
Output: trueExample 2:
1
2Input: p = [1,2], q = [1,null,2]
Output: falseExample 3:
1
2Input: p = [1,2,1], q = [1,1,2]
Output: false
Solution - JavaScript
1 | /** |
Solution - Ruby
1 | def is_same_tree(p, q) |
Solution - PHP
1 | function isSameTree($p, $q) { |