mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -04:00
Update bt_is_same_trees.py
This commit is contained in:
parent
faeb83a072
commit
3606be45c1
@ -2,15 +2,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# author: bt3gl
|
||||
|
||||
|
||||
def is_same_trees(p, q):
|
||||
|
||||
if not p and not q:
|
||||
return True
|
||||
|
||||
if (not p and q) or (not q and p):
|
||||
return False
|
||||
|
||||
if p.val != q.val:
|
||||
if (not p and q) or (not q and p) or p.val != q.val:
|
||||
return False
|
||||
|
||||
return self.is_same_trees(p.right, q.right) and self.is_same_trees(p.left, q.left)
|
||||
|
Loading…
x
Reference in New Issue
Block a user