๐ฌย ๋ฌธ์
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")
publicfunc solution(_ A :inout[Int])->Int{
A =A.sorted()
A =A.filter({ $0 >0})ifA.count <3{return0}foriin2..<A.count {ifA[i -2]+ A[i -1]>A[i]{return1}}return0}์์์๊ฐ : 15๋ถ
์๊ฐ ๋ณต์ก๋ : O(Nlog(N))*
ํ๊ฐํ : https://app.codility.com/demo/results/training5KSK4X-9HQ/
๐ฌย ๋ฌธ์ https://app.codility.com/programmers/lessons/6-sorting/triangle/
๐ฌย Idea๐ฌย ํ์ด์์์๊ฐ: 15๋ถ์๊ฐ ๋ณต์ก๋: O(Nlog(N))*ํ๊ฐํ: https://app.codility.com/demo/results/training5KSK4X-9HQ/