mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 12:16:14 -04:00
15 lines
328 B
Python
15 lines
328 B
Python
#!/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) or p.val != q.val:
|
|
return False
|
|
|
|
return is_same_trees(p.right, q.right) and is_same_trees(p.left, q.left)
|