[HackerRank][Python3] Fair Rations
2018. 9. 7. 00:48 |
프로그래밍/HackerRank
Problem :
https://www.hackerrank.com/challenges/fair-rations/problem
My Solution :
#!/usr/bin/env python3
def fair_rations(B):
count = 0
odd_index = -1
for i, loaves in enumerate(B):
if loaves % 2 == 1:
if odd_index != -1:
count += (i-odd_index)*2
odd_index = -1
else:
odd_index = i
if odd_index != -1:
return 'NO'
return count
N = int(input())
B = list(map(int, input().rstrip().split()))
result = fair_rations(B)
print(result)
'프로그래밍 > HackerRank' 카테고리의 다른 글
| [HackerRank][Python3] Maximum Perimeter Triangle (0) | 2018.09.08 |
|---|---|
| [HackerRank][Python3] Grid Challenge (0) | 2018.09.08 |
| [HackerRank][Python3] Strange Counter (0) | 2018.09.07 |
| [HackerRank][Python3] Happy Ladybugs (0) | 2018.09.07 |
| [HackerRank][Python3] Flatland Space Stations (0) | 2018.09.06 |
| [HackerRank][Python3] Lisa's Workbook (0) | 2018.09.06 |
| [HackerRank][Python3] Halloween Sale (0) | 2018.09.06 |
| [HackerRank][Python3] Minimum Distances (0) | 2018.09.06 |
최근에 달린 댓글 최근에 달린 댓글