문제
n번째까지 문자열 s를 반복했을 때 a의 개수 출력
제출한 코드
def repeatedString(s, n):
x = n//len(s) # 개의 s + @
dcnt = Counter(s)
reminder = n%len(s)
remcnt = Counter(s[:reminder])
if reminder == 0:
return dcnt['a']*x
else:
return dcnt['a']*x+remcnt['a']
'알고리즘 > 해커랭크' 카테고리의 다른 글
Arrays: Left Rotation (0) | 2020.03.16 |
---|---|
Cats and a Mouse (0) | 2020.03.16 |
Counting Valleys (0) | 2020.03.09 |
Drawing Book (0) | 2020.03.09 |
Sock Merchant (0) | 2020.03.08 |