단순
def pickingNumbers(a):
m = [0] * 100
for num in a:
m[num] += 1
cnt = 0
for i in range(1,n):
cnt = max(cnt, m[i - 1] + m[i])
return maxval
복잡
def pickingNumbers(a):
# Write your code here
_a = list(set(sorted(a)))
cnt = -1
subsets = []
for i in range(len(_a)):
temp = _a[i]
subset = [temp]
for j in range(i + 1, len(_a)):
if abs(temp - _a[j]) <= 1:
subset.append(_a[j])
subsets.append(subset)
for subset in subsets:
_sum = 0
for v in subset:
_sum += a.count(v)
cnt = max(cnt, _sum)
return cnt
'# 코딩 문제 관련 > 파이썬' 카테고리의 다른 글
[HackerRank-python] The Hurdle Race (0) | 2022.07.14 |
---|---|
[HackerRank-python] Climbing the Leaderboard (0) | 2022.07.11 |
[HackerRank-python] Forming a Magic Square (0) | 2022.07.10 |
[HackerRank-python] Cats and a Mouse (0) | 2022.07.10 |
[HackerRank-python] Electronics Shop (0) | 2022.07.10 |