Closed
Description
๐ฌย ๋ฌธ์
https://app.codility.com/programmers/lessons/4-counting_elements/perm_check/
๐ฌย Idea
- A๋ฅผ ๋ด๋ฆผ์ฐจ์์ผ๋ก ์ ๋ ฌํด์ ๊ฐ์ฅ ํฐ ์๋ฅผ ๋ฝ๋๋ค. A์ ์นด์ดํธ๊ฐ ๊ฐ์ฅ ํฐ ์์ ์ผ์นํ๋ฉด์, Set์ ํตํด ์ค๋ณต์ ๊ฑฐ๋ฅผ ํ ์นด์ดํธ์ A์ ์นด์ดํธ๊ฐ ๊ฐ์์ง ๊ฒ์ฌํด์ค๋ค. ์ด ์กฐ๊ฑด์ด ๋ชจ๋ ์ผ์นํ๋ฉด 1์, ๊ทธ๋ ์ง ์๋ค๋ฉด 0์ ๋ฐํํ๋ค.
๐ฌย ํ์ด
import Foundation
import Glibc
// you can write to stdout for debugging purposes, e.g.
// print("this is a debug message")
public func solution(_ A : inout [Int]) -> Int {
A = A.sorted(by: >)
return Set(A).count == A.count && A.count == A.first! ? 1 : 0
}
์์์๊ฐ
: 10๋ถ
์๊ฐ ๋ณต์ก๋
: O(N) or O(N * log(N))
ํ๊ฐํ
: https://app.codility.com/demo/results/trainingHDX4DB-V3F/