๋ฌธ์ :
https://programmers.co.kr/learn/courses/30/lessons/92335?language=swift
๋ถ์ :
swift์๋ ์ง์ ๋ณํ์ ์ฝ๊ฒ ํด์ฃผ๋ ํจ์๊ฐ ์๋ค. ๊ทธ๋์ ๋ค๋ฅธ์ธ์ด๋ณด๋ค ๊ฐ๊ฒฐํ๊ฒ ํผ๊ฑฐ ๊ฐ๋ค
Swift ์ฝ๋ :
//
// main.swift
// SOMA๐ฉ๐ป๐ป
//
// Created by JoSoJeong on 2022/04/15.
//
import Foundation
func isPrime(_ number: Int) -> Bool {
var bool = false
if number == 2 || number == 3 { return true }
let maxDivider = Int(sqrt(Double(number)))
bool = number > 1 && !(2...maxDivider).contains { number % $0 == 0 }
return bool
}
//์ง์ ๋ณํ
func solution(_ n:Int, _ k:Int) -> Int {
var answer = 0
let kcimal = String(n, radix: k)
let arr = kcimal.split(separator: "0")
for (idx, i) in arr.enumerated() {
if isPrime(Int(i)!) {
answer += 1
}
}
return answer
}
๊ฒฐ๊ณผ :
'Algorithm๐ฐ > ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค] C++ ๋์คํฌ ์ปจํธ๋กค๋ฌ (0) | 2022.04.22 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค] Swift 2022 kakao ์ฃผ์ฐจ ์๊ธ ๊ณ์ฐ (0) | 2022.04.19 |
[ํ๋ก๊ทธ๋๋จธ์ค] Swift ์์ ์ต๋ํ (0) | 2022.04.14 |
[ํ๋ก๊ทธ๋๋จธ์ค] Swift ํํ 2019 ์นด์นด์ค implementation (0) | 2022.04.14 |
[ํ๋ก๊ทธ๋๋จธ์ค] Swift 2020 ์นด์นด์ค ๊ดํธ๋ณํ (0) | 2022.04.14 |
๋๊ธ