MCPcopy Create free account
hub / github.com/Blankj/awesome-java-leetcode / Solution

Class Solution

src/com/blankj/easy/_0100/Solution.java:14–32  ·  view source on GitHub ↗

author: Blankj blog : http://blankj.com time : 2017/10/08 desc :

Source from the content-addressed store, hash-verified

12 * </pre>
13 */
14public class Solution {
15 public boolean isSameTree(TreeNode p, TreeNode q) {
16 if (p == null || q == null) return p == q;
17 if (p.val != q.val) return false;
18 return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
19 }
20
21 public static void main(String[] args) {
22 Solution solution = new Solution();
23 System.out.println(solution.isSameTree(
24 TreeNode.createTestData("[1,2,2,null,3,null,3]"),
25 TreeNode.createTestData("[1,2,2,null,3,null,3]"))
26 );
27 System.out.println(solution.isSameTree(
28 TreeNode.createTestData("[1,2,2,null,3,null,3]"),
29 TreeNode.createTestData("[1,2,2,null,3,null,null]"))
30 );
31 }
32}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected