Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- arr = [2, 3, 4, 2, 4, 2, 2, 5, 2]
- size = len(arr)
- times = 1
- lead = arr[0]
- for i in range(1, size):
- if times == 0:
- lead = arr[i]
- times += 1
- else:
- if arr[i] == lead:
- times += 1
- else:
- times -= 1
- if times == 0:
- print("No leader in array")
- exit()
- else:
- times = 0
- for i in range(0, size):
- if arr[i] == lead:
- times += 1
- if times > (size / 2):
- print("Leader {:d} in array".format(lead))
- else:
- print("No leader in array")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement