728x90
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' 카테고리의 다른 글
Swift로 코드 최적화하기 (0) | 2024.05.25 |
---|---|
[프로그래머스] 미로 탈출 (Swift) (2) | 2024.03.17 |
[백준] 7576, 토마토 (Swift) (0) | 2024.02.13 |
[백준] 3151, 합이 0 (Swift) (2) | 2024.01.27 |
[백준] 2644, 촌수계산(C++, BFS) (0) | 2023.09.02 |