finish extra/numbers-station-coded-messages

Submitting solution...
Submission: SUCCESSFUL. Completed in: 10 mins, 1 secs.
This commit is contained in:
Seongbeom Park 2022-05-10 01:53:11 +09:00
parent 70be0c07d8
commit 0d002d6988
2 changed files with 18 additions and 0 deletions

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)