Advertisement
Arsylk

A certain high Narkoman

Oct 11th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. arr = [2, 3, 4, 2, 4, 2, 2, 5, 2]
  2. size = len(arr)
  3.  
  4. times = 1
  5. lead = arr[0]
  6. for i in range(1, size):
  7.     if times == 0:
  8.         lead = arr[i]
  9.         times += 1
  10.     else:
  11.         if arr[i] == lead:
  12.             times += 1
  13.         else:
  14.             times -= 1
  15. if times == 0:
  16.     print("No leader in array")
  17.     exit()
  18. else:
  19.     times = 0
  20.     for i in range(0, size):
  21.         if arr[i] == lead:
  22.             times += 1
  23. if times > (size / 2):
  24.     print("Leader {:d} in array".format(lead))
  25. else:
  26.     print("No leader in array")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement