-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
๐ฌย ๋ฌธ์
https://app.codility.com/programmers/lessons/16-greedy_algorithms/tie_ropes/
๐ฌย Idea
๊ทธ๋ฆฌ๋ ์๊ณ ๋ฆฌ์ฆ์ ์ฌ์ฉํ์ฌ ๊ตฌ๊ฐํฉ์ ๊ตฌํ ๋ค ํฉ์ด K ์ด์์ด ๋๋ฉด ์นด์ดํธ๋ฅผ ์ฆ๊ฐ์ํจ๋ค. ๋ฐฐ์ด์ ๋๊น์ง ์ด๋ฅผ ๋ฐ๋ณตํ๋ค.
๐ฌย ํ์ด
public func solution(_ K : Int, _ A : inout [Int]) -> Int {
var sum = 0
var cnt = 0
for i in A {
sum += i
if sum >= K {
cnt += 1
sum = 0
}
}
return cnt
}
์์์๊ฐ
: 12๋ถ
์๊ฐ ๋ณต์ก๋
: O(N)
ํ๊ฐํ
: https://app.codility.com/demo/results/training6874HK-B65/