티스토리 뷰
A left rotation operation on an array of size n shifts each of the array's elements 1 unit to the left. For example, if 2 left rotations are performed on array [1,2,3,4,5], then the array would become [3,4,5,1,2].
Given an array of n integers and a number, d, perform d left rotations on the array. Then print the updated array as a single line of space-separated integers.
풀이
function main() {
const nd = readLine().split(' ');
const n = parseInt(nd[0], 10);
const d = parseInt(nd[1], 10);
const a = readLine().split(' ').map(aTemp => parseInt(aTemp, 10));
let temp = a.slice(0, d);
a.splice(0, d);
console.log(a.concat(temp).join(" "));
}
'1Day 1Algorithm' 카테고리의 다른 글
[DAY 2] 프로그래머스 : 문자열 내림차순으로 배치하기 (0) | 2020.05.20 |
---|---|
[DAY 1] 프로그래머스 : 평균 구하기 (0) | 2020.05.19 |
[DAY 33] 오픈채팅방 (2019 KAKAO BLIND RECRUITMENT) (0) | 2019.11.06 |
[DAY 32] 다트 게임 (2018 KAKAO BLIND RECRUITMENT) (0) | 2019.11.03 |
[DAY 31] 문자열 다루기 기본 (0) | 2019.11.01 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 자료구조
- redux-saga
- reduce()
- 운영체제
- 멀티프로그래밍
- React
- sort()
- 알고리즘
- js
- Props
- 웹팩
- 자바스크립트
- Algorithm
- 타입스크립트
- 리액트
- greedyAlgorithm
- 1day1algorithm
- 배열
- Webpack
- OS
- 컴퓨터공학
- sort
- Typescript
- 구간합
- javascript
- 시분할시스템
- 우아한테크러닝
- Array
- 프로그래머스
- 배치처리시스템
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함