func solution(_ citations:[Int]) -> Int {
var arr:[Int] = []
var result:[Int] = []
result.append(0)
arr.append(0)
var citations = citations.sorted(by: <)
// print(citations)
for i in 0...citations.count - 1 {
var hab = citations.count - i
// print("hab\(hab)")
for j in 0...citations[i]{
// print(j)
if j >= arr.last! && j <= hab {
result.append(j)
}
}
arr.append(citations[i])
}
// print(result)
return result.last!
}
[5,5,5,5] 배열의 답은 4입니다. max 함수를 사용하나 last 를 사용하나 답은 같은데 max 시간이 압도적으로 많이 걸려서 시간초과가 났습니다
'코테 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 가장큰수 스위프트 (0) | 2022.02.20 |
---|---|
[프로그래머스] 다리를지나는트럭 스위프트 (0) | 2022.02.17 |
[프로그래머스] 프린터 스위프트 (0) | 2022.02.16 |
[프로그래머스] 위장 스위프트 (0) | 2022.02.15 |
[프로그래머스] 행렬테두리회전하기 스위프트 (0) | 2022.02.13 |
댓글