티스토리 뷰

Codility-Lesson02-2. CyclicRotation



문제

A = {3,8,9,7,6} 배열을 K에 따라 위치를 옮기는 문제.


1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution {
    public int[] solution(int[] A, int K) {
        // write your code in Java SE 8
        
        int[] a = new int[A.length];
        
        for(int i = 0 ; i < A.length ; i++){
            a[(i+K)%a.length= A[i];
        }
        
        return a;
    }
}
cs


'프로그래밍 > 알고리즘' 카테고리의 다른 글

Codility-Lesson02-1. OddOccurrencessInArray  (0) 2017.10.18
Codility-Lesson01. BinaryGap  (0) 2017.10.18
2 * N 타일링  (0) 2017.05.19
[백준 7576번]토마토문제 풀기  (2) 2017.05.19
탐욕 알고리즘  (0) 2017.03.24
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
TAG
more
«   2024/07   »
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
글 보관함