Skip to content

Instantly share code, notes, and snippets.

@ShinJJang
Created January 11, 2020 06:53
Show Gist options
  • Save ShinJJang/95e7758b0333207bcd0695b537644aaa to your computer and use it in GitHub Desktop.
Save ShinJJang/95e7758b0333207bcd0695b537644aaa to your computer and use it in GitHub Desktop.
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A, int[] B) {
ArrayList<Integer> up_sizes = new ArrayList<>();
int lives = 0;
for(int i=A.length-1; i>=0; i--) {
if (B[i] == 0) {
up_sizes.add(A[i]);
continue;
}
for(int j=up_sizes.size()-1; j>=0; j--) {
if (up_sizes.get(j) > A[i]) {
break;
}
up_sizes.remove(j);
}
if (up_sizes.size() == 0) {
lives++;
}
}
lives += up_sizes.size();
return lives;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment