1. Character 타입은 Int로 변환이 불가능하다.
let str = "12345"
let intValue: Int = Int(str[str.index(str.startIndex, offsetBy: 0)]))! // 에러
let intValue: Int = Int(String(str[str.index(str.startIndex, offsetBy: 0)]))! // 정답
2. pow 함수는 첫 번째 인자가 Decimal 타입인데, 그냥 Double 쓰면 됨
let a = 10
let b = 5
let result = Int(pow(Double(a), Double(b)))
'🖥️ Computer Science > Algorithm' 카테고리의 다른 글
| [Algorithm] 비트마스킹 이론 & BOJ 11723 실습 (0) | 2024.12.30 |
|---|---|
| [Algorithm] 백준 32350 - Swift 풀이 (0) | 2024.12.28 |
| Swift로 코드 최적화하기 (1) | 2024.05.25 |
| [백준] 7576, 토마토 (Swift) (0) | 2024.02.13 |
| [백준] 2644, 촌수계산(C++, BFS) (2) | 2023.09.02 |