Where who wants to meet someone

순서 바꾸기 본문

728x90

문제

https://school.programmers.co.kr/learn/courses/30/lessons/181891

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

내 답안 / 다른 사람들의 답안

import Foundation

func solution(_ num_list:[Int], _ n:Int) -> [Int] {
    return Array(num_list[n...] + num_list[..<n])
}

- n번째 원소 이후의 값 뒤에 n번째 원소 이전까지의 값을 더한 배열을 구하는 것이기에 n... 슬라이스와 ..<n 슬라이스를 더해서 반환

 

import Foundation

func solution(_ num_list:[Int], _ n:Int) -> [Int] {
    return Array(num_list[n...]) + Array(num_list[..<n])
}

import Foundation

func solution(_ numList: [Int], _ n: Int) -> [Int] {
    let index = n % numList.count
    return Array(numList[index...] + numList[..<index])
}

 

 

점수: +1

'프로그래머스 알고리즘 문제 기록 > 코딩 기초 트레이닝' 카테고리의 다른 글

n 번째 원소까지  (2) 2024.01.24
왼쪽 오른쪽  (1) 2024.01.24
n 번째 원소부터  (1) 2024.01.23
배열 조각하기  (0) 2024.01.23
2의 영역  (0) 2024.01.23