https://school.programmers.co.kr/learn/courses/30/lessons/134240
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
분석


코드
import java.util.*;
class Solution {
public String solution(int[] food) {
String answer = "";
int count = 0;
ArrayList<Integer> arrList = new ArrayList<>();
ArrayList<Integer> tmpList = new ArrayList<>();
for(int i=0; i<food.length; i++){
if(food[i]<=1)
continue;
else
count = food[i]/2;
for(int j=0; j<count; j++){
arrList.add(i);
}
}
for(int i=arrList.size()-1; i>=0; i--){
tmpList.add(arrList.get(i));
}
arrList.add(0);
arrList.addAll(tmpList);
for(int item : arrList){
answer += item + "";
}
return answer;
}
}'알고리즘 > 문제' 카테고리의 다른 글
| [프로그래머스] 기사단원의 무기 / JAVA (0) | 2022.11.20 |
|---|---|
| [프로그래머스] 약수의 개수와 덧셈 / java (0) | 2022.11.17 |
| [프로그래머스] 삼총사 / java (0) | 2022.11.06 |
| [프로그래머스] 다음에 올 숫자 / java (0) | 2022.11.05 |
| [프로그래머스] 치킨 쿠폰 / java (0) | 2022.11.02 |