Notice
Recent Posts
Recent Comments
Link
반응형
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 프로그래머스 소수
- 오라클
- JSON특징
- 리눅스 rwx
- 빗썸 API 사용
- 파이썬 가상환경
- 리눅스 777
- 변동성 돌파전략
- Python
- Web Server란
- BigDecimal
- spring
- WAS WebServer 차이
- 프로그래머스 SQL
- 와스 웹서버의 차이
- string format
- JavaScript Obejct Notation
- 리눅스
- 파이썬
- 파이썬 주식
- pybithumb
- 즐겨찾기가 가장 많은 식당 정보 출력하기
- JSON 형식
- 트레이딩 봇 만들기
- beautifulsoup
- java
- 프로그래머스
- Web Service Architecture
- WAS란
- 단순 반복 자동화
Archives
- Today
- Total
IT 개발자_S
[코딜리티]CyclicRotation 본문
반응형
1.입력값 배열, 오른쪽 Rotation 횟수
2.오른쪽으로 Rotation 횟수를 인덱스화하여 계산
3.배열을 선언할때 Parameter로 받아쓰면 reference call 되므로 유의
4. index 개념을 활용하자
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
// 인덱스 계산
//int [] rotationA = A; // reference call 로 값이 변함
int[] rotationA = new int[A.length]; // 새롭게 선언
int index = 0;
for (int i =0; i < A.length; i++){
if( i +K >= A.length){
index= (i+K)%A.length;
}else{
index = i+K;
}
// System.out.println(i +" , " +index + " , " + A[i]);
rotationA[index] = A[i];
}
return rotationA;
}
}
반응형
'IT > 알고리즘_JAVA' 카테고리의 다른 글
[코딜리티] TapeEquilibrium (0) | 2020.05.10 |
---|---|
[코딜리티]PermMissingElem (0) | 2020.05.10 |
[코딜리티]Frog_jump (0) | 2020.05.10 |
[코딜리티]OddOccurrencesInArray (0) | 2020.05.09 |
[코딜리티] Binary Gap (0) | 2020.05.09 |
Comments