Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MARK: - Same tree
- func isSameTree(_ p: TreeNode?, _ q: TreeNode?) -> Bool {
- // сначала проверяем сами ноды, а потом уже уходим в рекурсию
- if p == nil && q == nil {
- return true
- }
- if p == nil || q == nil {
- return false
- }
- if p?.val != q?.val {
- return false
- }
- return isSameTree(p?.left, q?.left) && isSameTree(p?.right, q?.right)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement