/
githubmirror
/
interviews
Обзор
Документация
Войти
/
githubmirror
/
interviews
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
leetcode/depth-first-search/SameTree.java
30 строк
793 B
Kevin Naughton Jr
finish renaming files and directories
27 мар 2018, 19:52
27 мар 2018, 19:52
ec6dfb5
Код
Авторство
О чём код?
// Given two binary trees, write a function to check if they are equal or not. // Two binary trees are considered equal if they are structurally identical and the nodes have the same value. /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class SameTree { public boolean isSameTree(TreeNode p, TreeNode q) { if(p == null && q == null) { return true; } if(p == null && q != null || q == null && p != null) { return false; } if(p.val != q.val) { return false; } return isSameTree(p.left, q.left) && isSameTree(p.right, q.right); } }