티스토리 뷰

1Day 1Algorithm

[DAY 34] Left Rotation

walk_through_me 2019. 11. 9. 01:04

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.

 

 

Left Rotation | HackerRank

Given an array and a number, d, perform d left rotations on the array.

www.hackerrank.com

 

풀이

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(" ")); 
}
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
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
글 보관함