Created
August 22, 2023 17:57
-
-
Save youngvctr/8ef71f917dc3386f9f52c3b09abed57e to your computer and use it in GitHub Desktop.
Programmers | 택배상자
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Stack; | |
class Solution { | |
public int solution(int[] order) { | |
int answer = 0; | |
Stack<Integer> conveyor = new Stack<>(); | |
for(int i=1; i<=order.length; i++){ | |
conveyor.push(i); | |
while(!conveyor.isEmpty()){ | |
if(conveyor.peek() == order[answer]){ | |
answer++; | |
conveyor.pop(); | |
} else break; | |
} | |
} | |
return answer; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://school.programmers.co.kr/learn/courses/30/lessons/131704