Skip to content

Instantly share code, notes, and snippets.

@wkdalsgh192
Created January 2, 2021 02:07
Show Gist options
  • Select an option

  • Save wkdalsgh192/6ac3e05ac8af15a1cf406f71ecbc1f95 to your computer and use it in GitHub Desktop.

Select an option

Save wkdalsgh192/6ac3e05ac8af15a1cf406f71ecbc1f95 to your computer and use it in GitHub Desktop.
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