File tree 1 file changed +3
-25
lines changed
src/main/java/com/fishercoder/solutions 1 file changed +3
-25
lines changed Original file line number Diff line number Diff line change 1
1
package com .fishercoder .solutions ;
2
2
3
- /**
4
- * 402. Remove K Digits
5
- *
6
- * Given a non-negative integer num represented as a string, remove k digits from the number so that the new number is the smallest possible.
7
-
8
- Note:
9
- The length of num is less than 10002 and will be ≥ k.
10
- The given num does not contain any leading zero.
11
- Example 1:
12
-
13
- Input: num = "1432219", k = 3
14
- Output: "1219"
15
- Explanation: Remove the three digits 4, 3, and 2 to form the new number 1219 which is the smallest.
16
- Example 2:
17
-
18
- Input: num = "10200", k = 1
19
- Output: "200"
20
- Explanation: Remove the leading 1 and the number is 200. Note that the output must not contain leading zeroes.
21
- Example 3:
22
-
23
- Input: num = "10", k = 2
24
- Output: "0"
25
- Explanation: Remove all the digits from the number and it is left with nothing which is 0.
26
- */
27
3
public class _402 {
28
4
public static class Solution1 {
29
5
30
- /** credit: https://discuss.leetcode.com/topic/59412/a-greedy-method-using-stack-o-n-time-and-o-n-space */
6
+ /**
7
+ * credit: https://discuss.leetcode.com/topic/59412/a-greedy-method-using-stack-o-n-time-and-o-n-space
8
+ */
31
9
public String removeKdigits (String num , int k ) {
32
10
int digits = num .length () - k ;
33
11
char [] stack = new char [num .length ()];
You can’t perform that action at this time.
0 commit comments