Created
January 11, 2020 06:53
-
-
Save ShinJJang/95e7758b0333207bcd0695b537644aaa to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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