finish extra/numbers-station-coded-messages #24

Merged
seongbeom_park merged 2 commits from extra/numbers-station-coded-messages into main 2022-05-09 16:55:27 +00:00
2 changed files with 18 additions and 0 deletions
Showing only changes of commit 0d002d6988 - Show all commits

View File

@ -102,3 +102,6 @@ CFcSBwgCCBoHRhkKU1cGAA4AGU5YQR5THBwNFwoGGAxTQQMQVBUSBg4EAAwQRhUQVBUHFAQTGRpT QQM
### dont-get-volunteered
* Completed in: 2 hrs, 56 mins, 6 secs.
### numbers-station-coded-messages
* Completed in: 10 mins, 1 secs.

View File

@ -0,0 +1,15 @@
def solution(l, t):
for i in range(len(l)):
for j in range(i, len(l)):
if sum(l[i:j+1]) == t:
return [i, j]
return [-1, -1]
tests = [
([[1, 2, 3, 4], 15], [-1, -1]),
([[4, 3, 10, 2, 8], 12], [2, 3]),
]
for i, o in tests:
result = solution(*i)
print (i, result == o, result, o)