Codility - #2 Cyclic Rotation

고독한 키쓰차·2021년 7월 11일
0

코딩테스트

목록 보기
2/16

쉬운 문제 였다.
풀었던 사고과정은, 규칙성을 먼저 찾았다. 횟수가 몇으로 오던 결국엔 총 길이의 나머지 만큼 더 나아간다는것을 인지하여, 쉽게 풀 수 있었다.

class Solution {
    public int[] solution(int[] A, int K) {
        int N = A.length;
        int[] ans = new int[N];
        int temp;
        for(int i = 0; i < N; i++) {
        		temp = (i + K) % N;
        		ans[temp] = A[i];
        		
        }
        
        return ans;
    }
}
profile
Data Scientist or Gourmet

0개의 댓글