프로그래머스 (Swift)/기초
[Day4-1] n의 배수
은더기
2024. 1. 25. 08:54
문제
내 정답 코드
import Foundation
func solution(_ num:Int, _ n:Int) -> Int {
return num % n == 0 ? 1 : 0
}
#
1. %연산을 통해 해결하였다.
isMultiple이라는 기술을 통해 구현할 수 있다.
import Foundation
func solution(_ num:Int, _ n:Int) -> Int {
return num.isMultiple(of: n) ? 1 : 0
}
배운 기술
1. isMultiple(of: )
https://developer.apple.com/documentation/swift/int/ismultiple(of:)
isMultiple(of:) | Apple Developer Documentation
Returns if this value is a multiple of the given value, and otherwise.
developer.apple.com