func solution(_ nums:[Int]) -> Int {
var answer = -1
var three:[Int] = []
var sosu = 0
for i in 0...nums.count - 3 {
for j in (i + 1)...nums.count - 2 {
for k in (j + 1)...nums.count - 1 {
// print(nums[i], nums[j], nums[k])
three.append(nums[i] + nums[j] + nums[k])
}
}
}
// print(three)
for i in 0...three.count - 1 {
var tr = true
for j in 2...three[i] - 1{
if three[i] % j == 0 {
tr = false
break
}
}
if tr == true {
sosu = sosu + 1
}
}
//print(sosu)
return sosu
}
3중첩문 사용
'코테 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 모의고사 스위프트 (0) | 2022.01.12 |
---|---|
[프로그래머스] K번째수 스위프트 (0) | 2022.01.12 |
[프로그래머스] 내적 스위프트 (0) | 2022.01.11 |
[프로그래머스] 음양더하기 스위프트 (0) | 2022.01.11 |
[프로그래머스] 없는숫자더하기 스위프트 (0) | 2022.01.11 |
댓글