-
[Programmers] Swift 알고리즘 | Lv.0 카운트 업► Swift/Programmers 2024. 2. 22. 20:37반응형
🔒 문제 설명
정수 start_num와 end_num가 주어질 때, start_num부터 end_num까지의 숫자를 차례로 담은 리스트를 return하도록 solution 함수를 완성해주세요.
🔒 제한사항
- 0 ≤ start_num ≤ end_num ≤ 50
🔒 입출력 예
start_num end_num result 3 10 [3, 4, 5, 6, 7, 8, 9, 10]
🔒 입출력 예 설명
입출력 예 #1
- 3부터 10까지의 숫자들을 담은 리스트 [3, 4, 5, 6, 7, 8, 9, 10]를 return합니다.
🔐 solution of mine
(...).map{}
import Foundation func solution(_ start_num:Int, _ end_num:Int) -> [Int]{(start_num...end_num).map{$0}} solution(3,10) //output:[3, 4, 5, 6, 7, 8, 9, 10]
🔐 solution of others
[Int](...)
import Foundation func solution(_ start: Int, _ end: Int) -> [Int] {[Int](start...end)} solution(3,10) //output:[3, 4, 5, 6, 7, 8, 9, 10]
🔐 solution of others
Array(...)
import Foundation func solution(_ start: Int, _ end: Int) -> [Int] {Array(start...end)} solution(3,10) //output:[3, 4, 5, 6, 7, 8, 9, 10]
반응형'► Swift > Programmers' 카테고리의 다른 글
[Programmers] Swift 알고리즘 | Lv.0 대문자로 바꾸기 (0) 2024.02.22 [Programmers] Swift 알고리즘 | Lv.0 길이에 따른 연산 (0) 2024.02.22 [Programmers] Swift 알고리즘 | Lv.0 n의 배수 (0) 2024.02.22 [Programmers] Swift 알고리즘 | Lv.0 소문자로 바꾸기 (0) 2024.02.22 [Programmers] Swift 알고리즘 | Lv.0 정수 부분 (0) 2024.02.22