Created
August 10, 2011 19:18
-
-
Save maraca/1137868 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def arr_leader(values): | |
| storage = {} | |
| max_sum_key = values[0] | |
| max_sum_val = 1 | |
| for i in values: | |
| if storage.get(i) is None: | |
| storage[i] = 0 | |
| storage[i] += 1 | |
| # stores the current highest sum | |
| if storage[i] > max_sum_val: | |
| max_sum_key = i | |
| max_sum_val = storage[i] | |
| if max_sum_val > len(values) / 2: | |
| return max_sum_key | |
| return -1 | |
| if __name__ == '__main__': | |
| print arr_leader([1, 2, 3 , 5, 6 ,7, 3, 3 ,3 , 3, 3 ,3 ,3 ,3 ]) | |
| print arr_leader([1, 2, 3 ,4 ]) | |
| ############################# | |
| > python2.6 ten_minutes.py | |
| 3 | |
| -1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment