82. 머쓱이보다 키 큰 사람

 


import Foundation

func solution(_ array:[Int], _ height:Int) -> Int {
    
    var answer : Int = 0
    
    for i in array.indices{
        if array[i] > height {
            answer += 1
        }
    }

    return answer
}


for문과 if문을 통해 문제를 해결하였다.

다른코드를 보니 filter로 하였다 다음번에 해봐야겠다.

또한 for if문을 섞어 for문에 where로 했다. 예전에 해본거 같은데 다시 기억해둬야겠다.

func solution(_ array: [Int], _ height: Int) -> Int { array.filter { $0 > height }.count }
//

import Foundation

func solution(_ array:[Int], _ height:Int) -> Int {
    var result = 0
    for h in array where h > height {
        result += 1
    }
    return result
}