[HackerRank][Python3] Hackerland Radio Transmitters
2018. 5. 23. 00:11 |
프로그래밍/HackerRank
Problem :
https://www.hackerrank.com/challenges/hackerland-radio-transmitters/problem
My Solution :
#!/usr/bin/env python3 def hackerlandRadioTransmitters(x, k): x = sorted(x) c = 1 t = x[0] for i in range(len(x)): if x[i] == t + k: t = x[i] elif x[i] > t + k: t = x[i-1] else: continue for j in range(i, len(x)): if x[j] > t + k: t = x[j] c += 1 break return c n, k = map(int, input().strip().split()) x = list(map(int, input().strip().split())) print(hackerlandRadioTransmitters(x, k))
My Solution2 :
#!/usr/bin/env python3 def hackerlandRadioTransmitters(x, k, n): x = sorted(x) c, i = 0, 0 while i < n: t = x[i] while i < n and x[i] <= t + k: i += 1 t = x[i-1] while i < n and x[i] <= t + k: i += 1 c += 1 return c n, k = map(int, input().strip().split()) x = list(map(int, input().strip().split())) print(hackerlandRadioTransmitters(x, k, n))
'프로그래밍 > HackerRank' 카테고리의 다른 글
[HackerRank][Python3] Minimum Absolute Difference in an Array (0) | 2018.05.29 |
---|---|
[HackerRank][Python3] Big Sorting (0) | 2018.05.29 |
[HackerRank][Python3] CamelCase (0) | 2018.05.27 |
[HackerRank][Python3] Journey to the Moon (0) | 2018.05.25 |
[HackerRank][Python3] Sherlock and Cost (0) | 2018.05.21 |
[HackerRank][Python3] Maximum Subarray Sum (0) | 2018.05.18 |
[HackerRank][Python3] Equal (0) | 2018.05.16 |
[HackerRank][Python3] The Coin Change Problem (0) | 2018.05.15 |
최근에 달린 댓글 최근에 달린 댓글