Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Algorithm] PermCheck #135

Closed
hwangJi-dev opened this issue Mar 22, 2023 · 0 comments
Closed

[Algorithm] PermCheck #135

hwangJi-dev opened this issue Mar 22, 2023 · 0 comments

Comments

@hwangJi-dev
Copy link
Owner

hwangJi-dev commented Mar 22, 2023

๐Ÿ’ฌย ๋ฌธ์ œ

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant