fork download
  1. # your code goes here
  2. class Node:
  3. def __init__(self):
  4. self.left = None
  5. self.right = None
  6. self.num = -1
  7.  
  8. class Solution:
  9.  
  10. def insert(self, string, i, node, num):
  11. if i == len(string):
  12. node.num = num
  13. return
  14. if string[i] == "0":
  15. if not node.left:
  16. node.left = Node()
  17. self.insert(string, i+1, node.left, num)
  18. else:
  19. if not node.right:
  20. node.right = Node()
  21. self.insert(string, i+1, node.right, num)
  22.  
  23. def search_max(self, string, i, node):
  24. if i == len(string):
  25. return node.num
  26. if string[i] == "0":
  27. if node.right:
  28. return self.search_max(string, i+1, node.right)
  29. else:
  30. return self.search_max(string, i+1, node.left)
  31. else:
  32. if node.left:
  33. return self.search_max(string, i+1, node.left)
  34. else:
  35. return self.search_max(string, i+1, node.right)
  36.  
  37.  
  38.  
  39.  
  40. def convert_bin(self, num, b):
  41. ans = ""
  42. for _ in range(b):
  43. ans += str(num%2)
  44. num //= 2
  45. return ans[::-1]
  46.  
  47. def QueryAnswer(self, arr):
  48. pass
  49. #Plz help implement this query function
Success #stdin #stdout 0.05s 9724KB
stdin
Standard input is empty
stdout
Standard output is empty