ํฐ์คํ ๋ฆฌ ๋ทฐ
๐จ๐ป ์ฝ๋ฉํ
์คํธ/Codility
Lesson 9: Maximum Slice Problem → Max Slice Sum
dirmathfl 2020. 6. 11. 22:22728x90
๋ฐ์ํ
๋ฌธ์
๋ฌธ์ ํ์ด
Max Profit ๋ฌธ์ ์ ๋์ผํ๊ฒ ๋ธ๋ฃจํธ ํฌ์ค๋ก ํ์ง ์๊ณ , ์นด๋ฐ์ธ ์๊ณ ๋ฆฌ์ฆ ์ฌ์ฉํ๋ฉด ์ฝ๊ฒ ํ ์ ์๋ค.
์ฝ๋
def solution(A):
max_sum = sub_sum = A.pop(0)
for num in A:
sub_sum = max(sub_sum + num, num)
max_sum = max(max_sum, sub_sum)
return max_sum
728x90
๋ฐ์ํ
'๐จโ๐ป ์ฝ๋ฉํ ์คํธ > Codility' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Lesson 10: Prime and composite numbers โ Min Perimeter Rectangle (0) | 2020.06.14 |
---|---|
Lesson 10: Prime and composite numbers โ Count Factors (0) | 2020.06.14 |
Lesson 9: Maximum Slice Problem โ Max Profit (0) | 2020.06.11 |
Lesson 8: Leader โ Equil Leader (0) | 2020.06.10 |
Lesson 8: Leader โ Dominator (0) | 2020.06.10 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ์ฌ๋ผ์จ ๊ธ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ