Birthday Chocolate
- 초콜렛 바는 연속되어야 한다.
- list 의 끝 인덱스가 넘어가면 마지막 인덱스까지 추출한다.\
- sum, len을 반환하여 로직을 세운다.
import math
import os
# Complete the birthday function below.
def birthday(s, d, m):
count = 0
for i in range(len(s)):
temp = s[i:i+m]
if sum(temp) == d:
if len(temp) == m:
count += 1
return count
if __name__ == '__main__':
n = int(input().strip())
s = list(map(int, input().rstrip().split()))
dm = input().rstrip().split()
d = int(dm[0])
m = int(dm[1])
result = birthday(s, d, m)
'HackerRank Algorithm' 카테고리의 다른 글
[HackerRank] 22. Between Two Sets (0) | 2020.04.07 |
---|---|
[HackerRank] 21. Birthday cake candles (0) | 2020.04.01 |
[HackerRank] 19. Bon Appétit (0) | 2020.04.01 |
[HackerRank] 18. Breaking the Records (0) | 2020.04.01 |
[HackerRank] 17. Counting Valleys (0) | 2020.04.01 |
댓글