Skip to content

Commit a2bf0a7

Browse files
refactor 402
1 parent b4c328a commit a2bf0a7

File tree

1 file changed

+3
-25
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+3
-25
lines changed

src/main/java/com/fishercoder/solutions/_402.java

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,11 @@
11
package com.fishercoder.solutions;
22

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-
*/
273
public class _402 {
284
public static class Solution1 {
295

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+
*/
319
public String removeKdigits(String num, int k) {
3210
int digits = num.length() - k;
3311
char[] stack = new char[num.length()];

0 commit comments

Comments
 (0)