Created
June 14, 2017 05:53
-
-
Save tlkahn/4b26ddbba4cb63ff5f9c8418b61febd8 to your computer and use it in GitHub Desktop.
Hackerland Radio Transmitters python
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 solution(k, arr, origin=0): | |
| arr = sorted(list(set(arr))) | |
| result = 1 | |
| cur = 0 | |
| origin = 0 | |
| for i in range(1, len(arr)): | |
| f = False | |
| if arr[i] - arr[origin] <= k: | |
| pass | |
| else: | |
| origin = i - 1 | |
| j = 1 | |
| while origin + j < len(arr): | |
| if arr[origin + j] - arr[origin] <= k: | |
| pass | |
| else: | |
| origin = origin + j | |
| i = origin + j + 1 | |
| result += 1 | |
| f = True | |
| break | |
| j += 1 | |
| if f: continue | |
| return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment