Skip to content

Commit

Permalink
feat: problem 1457
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwin-nair98 committed Jan 24, 2024
1 parent 121a9c2 commit 70e1e5e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions 1457_Pseudo PAlindromic Path Binary Tree/Solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def pseudoPalindromicPaths(self, root):
count = 0
stack = [(root, 0)]
while stack:
node, path = stack.pop()
if node:
path ^= 1 << node.val
if not node.left and not node.right:
if path & (path - 1) == 0:
count += 1
else:
stack.append((node.right, path))
stack.append((node.left, path))
return count

0 comments on commit 70e1e5e

Please sign in to comment.