-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
๐ฌย ๋ฌธ์
https://app.codility.com/programmers/lessons/3-time_complexity/perm_missing_elem/
๐ฌย Idea
- data๊ฐ 100,000๊ฐ ์ด๋ด์ด๋ฏ๋ก O(N)์ ์๊ฐ๋ณต์ก๋๋ฅผ ๊ฐ์ง๋ฉด ๋๊ฒ ๋ค๊ณ ํ๋จํ๋ค.
- ๋ฐ๋ผ์ A๋ฅผ ์ค๋ฆ์ฐจ์์ผ๋ก ์ ๋ ฌํ ๋ค for๋ฌธ์ ๋๋ฉฐ index์ ์ผ์นํ์ง ์๋ ๋ถ๋ถ์ ์ฐพ์ ๋ฐํํด์ฃผ์๋ค.
๐ฌย ํ์ด
import Foundation
import Glibc
public func solution(_ A : inout [Int]) -> Int {
A = A.sorted()
for i in 0..<A.count {
if i + 1 != A[i] {
return i + 1
}
}
return A.count + 1
}
์์ ์๊ฐ
: 10๋ถ
์๊ฐ ๋ณต์ก๋
: O(N) or O(N * log(N))
ํ๊ฐํ
: https://app.codility.com/demo/results/trainingNFYZ26-4QK/