Created
January 2, 2021 02:07
-
-
Save wkdalsgh192/6ac3e05ac8af15a1cf406f71ecbc1f95 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
| import java.util.*; | |
| class Solution { | |
| public String solution(String number, int k) { | |
| char[] arr = number.toCharArray(); | |
| Stack<Integer> list = new Stack<>(); | |
| for (int i = 0; i < arr.length; i++) { | |
| int curr = (int) arr[i] - '0'; | |
| while (!list.isEmpty() && k>0 && list.peek() < curr) { | |
| list.pop(); | |
| k -= 1; | |
| } | |
| list.push(curr); | |
| } | |
| while (k > 0) { | |
| list.pop(); | |
| k-=1; | |
| } | |
| StringBuilder sb = new StringBuilder(); | |
| for(int i : list) sb.append(i); | |
| return sb.toString(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment