Skip to content

Instantly share code, notes, and snippets.

@youngvctr
Created August 22, 2023 17:57
Show Gist options
  • Save youngvctr/8ef71f917dc3386f9f52c3b09abed57e to your computer and use it in GitHub Desktop.
Save youngvctr/8ef71f917dc3386f9f52c3b09abed57e to your computer and use it in GitHub Desktop.
Programmers | 택배상자
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;
}
}
@youngvctr
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment