https://school.programmers.co.kr/learn/courses/30/lessons/120844
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
class Solution {
private static final String RIGHT = "right";
private static final String LEFT = "left";
public int[] solution(int[] numbers, String direction) {
int size = numbers.length;
int[] answer = new int[size];
int dir = 0;
if(RIGHT.equals(direction)){
dir = -1;
}else{
dir = 1;
}
for(int i = 0 ; i < size ; i++){
int index = i + dir;
if(index < 0){
index += size;
}
if(index >= size){
index -= size;
}
answer[i] = numbers[index];
}
return answer;
}
}
'알고리즘' 카테고리의 다른 글
프로그래머스 가장 가까운 같은 글자(JAVA) (0) | 2022.12.20 |
---|---|
프로그래머스 최댓값 만들기 (JAVA) (0) | 2022.12.19 |
프로그래머스 로그인 성공?(JAVA) (0) | 2022.12.17 |
프로그래머스 A로 B만들기 (JAVA) (0) | 2022.12.16 |
프로그래머스 가위 바위 보 (JAVA) (0) | 2022.12.15 |