Skip to content

[Algorithm] PermCheckย #135

Closed
Closed
@hwangJi-dev

Description

@hwangJi-dev

๐Ÿ’ฌย ๋ฌธ์ œ

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/

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions