티스토리 뷰
728x90
알고리즘 문제 URL
https://school.programmers.co.kr/learn/courses/30/lessons/12925?language=swift
문제 사진
내 풀이
func solution(_ s:String) -> Int {
guard let result = Int(s) else { return 0 }
return result
}
다른사람의 풀이
func solution(_ s:String) -> Int {
return Int(s)!
}
배운것
String → Int로 변환하기 위해 Int( ) 메서드를 사용합니다.
String의 경우 아래와 같이 Int로 변환할 수 없을 가능성도 있기 때문에 Optional 처리가 되어 결과값이 나옵니다.
Int(" 100") // Includes whitespace
Int("21-50") // Invalid format
Int("ff6600") // Characters out of bounds
Int("10000000000000000000000000") // Out of range
// nil
// nil
// nil
// nil
728x90
'알고리즘' 카테고리의 다른 글
[Swift 알고리즘] - 자릿수 더하기 (Programmers) (0) | 2022.10.11 |
---|---|
[Swift 알고리즘] - 내적 (Programmers) (0) | 2022.10.10 |
[Swift 알고리즘] - 알수없는 숫자 더하기 (Programmers) (1) | 2022.10.01 |
[Swift 알고리즘] - Squares of a Sorted Array (Leetcode) (0) | 2022.05.20 |
[Swift 알고리즘] - Find Numbers with Even Number of Digits(Leetcode) (0) | 2022.05.19 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- swift programmers
- Swift 프로퍼티
- RTCCameraVideoCapturer
- removeLast()
- swift reduce
- Swift 알고리즘
- swift 고차함수
- Swift inout
- Swift ModernRIBs
- Swift
- Swift Leetcode
- Swift final
- swift protocol
- Swift init
- Swift joined()
- Swift 프로그래머스
- Combine: Asynchronous Programming with Swift
- Swift RIBs
- swift property
- CS 네트워크
- swift (programmers)
- Swift 내림차순
- Class
- 원티드 프리온보딩
- 2023년 회고
- Swift joined
- iOS error
- Swift Error Handling
- ios
- RIBs tutorial
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
글 보관함