-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
๐ฌย ๋ฌธ์
https://app.codility.com/programmers/lessons/6-sorting/triangle/
๐ฌย Idea
- ๋ฐฐ์ด์ ์ ๋ ฌํ ๋ค ์์๊ฐ์ ํํฐ๋งํด์ค๋ค.
- ์ด ๋ ๋ฐฐ์ด์ ๊ฐ์๊ฐ 3๊ฐ(์ผ๊ฐํ ์ถฉ์กฑ ์กฐ๊ฑด) ๋ฏธ๋ง์ด๋ผ๋ฉด 0์ ๋ฆฌํดํ๋ค.
- ๋ฐฐ์ด์ ๊ฐ์๊ฐ ์ผ๊ฐํ ๊ฐ์๋ฅผ ์ถฉ์กฑํ๋ค๋ฉด, ๋ฐฐ์ด์ ๋๋ฉด์ ์ธ์ ํ ์์ ๋์์ ํฉ๋ณด๋ค ๊ทธ ๋ค์ ์์ ๊ฐ์ด ํฌ๋ค๋ฉด 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()
A = A.filter({ $0 > 0 })
if A.count < 3 { return 0 }
for i in 2..<A.count {
if A[i - 2] + A[i - 1] > A[i] {
return 1
}
}
return 0
}
์์์๊ฐ
: 15๋ถ
์๊ฐ ๋ณต์ก๋
: O(Nlog(N))*
ํ๊ฐํ
: https://app.codility.com/demo/results/training5KSK4X-9HQ/