[프로그래머스 LV0] 중복된 숫자 개수

jonghwan·2022년 10월 5일
0

프로그래머스

목록 보기
12/71
post-thumbnail

1. 문제 설명

중복된 숫자 개수

2. 문제 분석

중복되는 값을 빈 배열에 추가해주고 원소의 개수를 반환해준다.

3. 나의 풀이

import Foundation

func solution(_ array:[Int], _ n:Int) -> Int {
    var arr: [Int] = []
    
    for i in array {
        if i == n {
            arr.append(Int(i))
        }
    }
    return arr.count
}

4. 다른 사람의 풀이

import Foundation

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

오늘 클로저에 대해 배웠는데.. 빨리 써먹을 수 있는 날이..

0개의 댓글