Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Node():
- def __init__(self, data, left=None, right=None):
- self.data = data
- self.left = left
- self.right = right
- total_iso_right_rotated_count = 0
- def count_iso_right_rotated(node):
- if node == None:
- return 0
- if node.right == None:
- return -1
- if node.left == None:
- return 1
- # first go right once
- go_right_count = count_iso_right_rotated(node.right) + 1
- # then go left all the way
- go_left_count = count_iso_right_rotated(node.right.left)
- # check if equal to zero
- if go_left == 0:
- total_iso_right_rotated_count += 1
- return go_left_count
- if __name__ == '__main__':
- root = Node(1)
- root.left = Node(2)
- root.right = Node(3)
- count_iso_right_rotated(root)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement