Trulyawesome

[Swift] H-Index 본문

알고리즘/프로그래머스

[Swift] H-Index

ethkelitt 2020. 9. 15. 19:46
1
2
3
4
5
6
7
8
9
10
11
12
import Foundation
 
func solution(_ citations:[Int]) -> Int {
    let data = citations.sorted { $0 > $1 }
    
    for i in 0..<data.count {
        if i >= data[i] {
            return i
        }
    }
    return data.count
}
cs

내림차순 정렬해서 H index값을 찾기만 하면되는 문제입니다. 😄