๐ฌย ๋ฌธ์
https://app.codility.com/programmers/lessons/16-greedy_algorithms/max_nonoverlapping_segments/
๐ฌย Idea
- ์ ๋ถ์ ์ค์ฒฉ๋์ง ์์ ์ต๋๊ฐ์๋ฅผ ๊ตฌํ๋ ๋ฌธ์ . ๋ฐฐ์ด์ ์ฒซ end์ ๋ค์ ์ธ๋ฑ์ค์ start๋ฅผ ๋น๊ตํด ์ต๋ ๊ฐ์๋ฅผ ์ฐพ์์ฃผ๋ฉด ๋๋ค.
๐ฌย ํ์ด
publicfunc solution(_ A :inout[Int], _ B :inout[Int])->Int{ifA.isEmpty {return0}varend=B[0]varcnt=1foriin1..<A.count {ifA[i]> end {
cnt +=1
end =B[i]}}return cnt
}์๊ฐ ๋ณต์ก๋ : O(N)
ํ๊ฐํ : https://app.codility.com/demo/results/trainingR64NKR-G29/
๐ฌย ๋ฌธ์ https://app.codility.com/programmers/lessons/16-greedy_algorithms/max_nonoverlapping_segments/
๐ฌย Idea๐ฌย ํ์ด์๊ฐ ๋ณต์ก๋: O(N)ํ๊ฐํ: https://app.codility.com/demo/results/trainingR64NKR-G29/