230720 햄버거 만들기

Jongleee·2023년 7월 20일
0

TIL

목록 보기
316/737
public int solution(int[] ingredient) {
	int answer = 0;
	Stack<Integer> inStack = new Stack<Integer>();

	for (int in : ingredient) {
		inStack.push(in);

		if (inStack.size() >= 4) {
			if (inStack.get(inStack.size() - 4) == 1 &&
				inStack.get(inStack.size() - 3) == 2 &&
				inStack.get(inStack.size() - 2) == 3 &&
				inStack.get(inStack.size() - 1) == 1) {
					answer++;
					inStack.pop();
					inStack.pop();
					inStack.pop();
					inStack.pop();
			}
		}
	}

	return answer;
}

출처:https://school.programmers.co.kr/learn/courses/30/lessons/133502

0개의 댓글