상세 컨텐츠

본문 제목

[Codility]CyclicRotation

Development/알고리즘

by J-Developer 2020. 6. 27. 17:10

본문

반응형

[문제]

 

[답안작성]

class Solution {
    public int[] solution(int[] A, int K) {
        
        if( A.length == K || A.length == 1 || A.length == 0 ) {
            return A;
        }
        
        int temp = 0;
        
        for( int i = 0; i < K; i++ ) {
         
         for( int j = 0; j < A.length; j++ ) {
             
             int t = 0;
             
             if( j == A.length - 1 ) {
                 
                 A[0] = A[j];
                 A[j] = temp;
                 
             }
             else {
                 
                 t = A[j];
                 A[j] = temp;
                 temp = t;
                 
             }
             
         }
            
        }
        
        return A;
        
    }
}
반응형

'Development > 알고리즘' 카테고리의 다른 글

[Codility] TapeEquilibrium  (0) 2020.06.28
[Codility]PermMissingElem  (0) 2020.06.28
[Codility]FrogJmp  (0) 2020.06.27
[Codiliy]OddOccurrencesInArray  (0) 2020.06.27
[Codility]BinaryGap  (0) 2020.06.27

관련글 더보기

댓글 영역