프로그래밍/HackerRank
[HackerRank][Python3] Hackerland Radio Transmitters
snoopybox
2018. 5. 23. 00:11
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))