Skip to content

Commit 1de8d23

Browse files
Create PseudoPalindromicPathsInABinaryTree.py
1 parent 178a647 commit 1de8d23

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Definition for a binary tree node.
2+
import heapq
3+
import unittest
4+
5+
# Read about enumerate in python
6+
from collections import defaultdict
7+
from typing import List
8+
9+
class TreeNode:
10+
def __init__(self, val=0, left=None, right=None):
11+
self.val = val
12+
self.left = left
13+
self.right = right
14+
15+
class PseudoPalindromicPathsInABinaryTree(unittest.TestCase):
16+
17+
def pseudoPalindromicPaths(self, root: TreeNode) -> int:
18+
19+
def helper(root: TreeNode, states: int, result: List[int]):
20+
if root is None:
21+
return
22+
23+
states ^= 1 << (root.val - 1)
24+
if root.left is None and root.right is None:
25+
if states & (states - 1) == 0:
26+
result[0] += 1
27+
else:
28+
return
29+
30+
helper(root.left, states, result)
31+
helper(root.right, states, result)
32+
33+
return
34+
35+
result = [0]
36+
helper(root, 0, result)
37+
return result[0]
38+
39+
def test_Leetcode(self):
40+
print([1])
41+
42+
if __name__ == '__main__':
43+
unittest.main()

0 commit comments

Comments
 (0)