Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. class Node():
  2.   def __init__(self, data, left=None, right=None):
  3.     self.data = data
  4.     self.left = left
  5.     self.right = right
  6.  
  7. total_iso_right_rotated_count = 0
  8.  
  9. def count_iso_right_rotated(node):
  10.   if node == None:
  11.     return 0
  12.   # first go right once
  13.   go_right_count = count_iso_right_rotated(node.right) + 1
  14.   # then go left all the way
  15.   go_left_count = count_iso_right_rotated(node.left) - 1
  16.   # check if equal to zero
  17.   if go_left == 0:
  18.     total_iso_right_rotated_count += 1
  19.   return go_left_count
  20.  
  21. if __name__ == '__main__':
  22.   root = Node(1)
  23.   root.left = Node(2)
  24.   root.right = Node(3)
  25.   count_iso_right_rotated(root)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement