Create bt_is_same_trees.py

This commit is contained in:
marina 2023-08-03 19:36:17 -07:00 committed by GitHub
parent 390316781e
commit cd2e4557dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

16
trees/bt_is_same_trees.py Normal file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env python3
# -*- 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:
return False
return self.is_same_trees(p.right, q.right) and self.is_same_trees(p.left, q.left)