티스토리 뷰

728x90

[Swift 알고리즘] - Find Numbers with Even Number of Digits(Leetcode)

 

https://leetcode.com/explore/learn/card/fun-with-arrays/521/introduction/3237/

 

Explore - LeetCode

LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore.

leetcode.com

 

 

내 풀이

class Solution {
  func findNumbers(_ numbs: [Int]) -> Int {
    return numbs.filter { String($0).count % 2 == 0 }.count
  
  }
}

 

 

1. input의 배열 요소의 숫자자리수를 count해 짝수인것만 필터 후 

2. 필터된 배열의 count만 return 하였습니다.

728x90