mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-02 14:56:27 -04:00
Create bt_is_same_trees.py
This commit is contained in:
parent
390316781e
commit
cd2e4557dc
1 changed files with 16 additions and 0 deletions
16
trees/bt_is_same_trees.py
Normal file
16
trees/bt_is_same_trees.py
Normal 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)
|
Loading…
Add table
Add a link
Reference in a new issue