코딩테스트-알고리즘/프로그래머스

[프로그래머스/Lv.1] 푸드 파이트 대회

닉네임생각즁 2024. 4. 1. 23:51

 

https://school.programmers.co.kr/learn/courses/30/lessons/134240?language=java

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

 

class Solution {
    public String solution(int[] food) {
        String answer = "";
        
        for (int i = 0; i < food.length; i++) {
            food[i] = food[i] / 2;
        }
        
        for (int i = 1; i < food.length; i++) {
            int index = 0;
            while (index < food[i]) {
                answer += i;
                index++;
            }
        }
        
        answer += "0";
        
        for (int i = food.length-1; i > 0; i--) {
            int index = 0;
            while (index < food[i]) {
                answer += i;
                index++;
            }
        }
        
        return answer;
    }
}