Skip to content

22.12.12 - [PG] 푸드 파이트 대회 #272

@suhyunsim

Description

@suhyunsim

문제

핵심 아이디어

어려운 점, 실수

풀이

import java.util.*;

class Solution {
    public String solution(int[] food) {
        Queue<Integer> queue = new LinkedList<>();
        for (int i = 1; i < food.length; i++) {
            int num = i;
            if (food[i] % 2 == 0) {
                for (int j = 0; j < food[i] / 2; j++) {
                    queue.add(num);            
                }
            } else {
                for (int j = 0; j < (food[i] - 1) / 2; j++) {
                    queue.add(num);            
                }                
            }
        }
        StringBuilder sb = new StringBuilder();
        Stack<Integer> stack = new Stack<>();
        for (Integer i : queue) {
            sb.append(i);
            stack.add(i);
        }
        sb.append("0");
        while(!stack.isEmpty()) {
            sb.append(stack.pop());
        }
        return String.valueOf(sb);
    }
}

Metadata

Metadata

Assignees

Labels

lv.1프로그래머스 - level 1성공맞은 문제스택stackQueue

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions