๐ฌย ๋ฌธ์
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
publicfunc solution(_ A :inout[Int])->Int{
A =A.sorted()foriin0..<A.count {if i +1!=A[i]{return i +1}}returnA.count +1}์์ ์๊ฐ : 10๋ถ
์๊ฐ ๋ณต์ก๋ : O(N) or O(N * log(N))
ํ๊ฐํ : https://app.codility.com/demo/results/trainingNFYZ26-4QK/
๐ฌย ๋ฌธ์ https://app.codility.com/programmers/lessons/3-time_complexity/perm_missing_elem/
๐ฌย Idea๐ฌย ํ์ด์์ ์๊ฐ: 10๋ถ์๊ฐ ๋ณต์ก๋: O(N) or O(N * log(N))ํ๊ฐํ: https://app.codility.com/demo/results/trainingNFYZ26-4QK/