iOS 개발 공부
[Swift] 카드뭉치 본문
import Foundation
func solution(_ cards1:[String], _ cards2:[String], _ goal:[String]) -> String {
let error = cards1.count + cards2.count + goal.count
let index1 = cards1.map { goal.firstIndex(of: $0) ?? error }
let index2 = cards2.map { goal.firstIndex(of: $0) ?? error }
let result1 = index1.sorted(by: <)
let result2 = index2.sorted(by: <)
return index1 == result1 && index2 == result2 ? "Yes" : "No"
}'프로그래머스 > Lv.1' 카테고리의 다른 글
| [Swift] 달리기 경주 (0) | 2023.04.25 |
|---|---|
| [Swift] 덧칠하기 (0) | 2023.04.15 |
| [Swift] 추억점수 (0) | 2023.04.14 |
| [Swift] X만큼 간격이 있는 N개의 숫자 (0) | 2023.02.27 |
| [Swift] K번째 수 (0) | 2023.02.27 |