402. Remove K Digits Medium

@problem@discussion
#String#Stack#Greedy#Monotonic Stack



1/**
2 * [402] Remove K Digits
3 *
4 * Given string num representing a non-negative integer num, and an integer k, return the smallest possible integer after removing k digits from num.
5 *  
6 * Example 1:
7 * 
8 * Input: num = "1432219", k = 3
9 * Output: "1219"
10 * Explanation: Remove the three digits 4, 3, and 2 to form the new number 1219 which is the smallest.
11 * 
12 * Example 2:
13 * 
14 * Input: num = "10200", k = 1
15 * Output: "200"
16 * Explanation: Remove the leading 1 and the number is 200. Note that the output must not contain leading zeroes.
17 * 
18 * Example 3:
19 * 
20 * Input: num = "10", k = 2
21 * Output: "0"
22 * Explanation: Remove all the digits from the number and it is left with nothing which is 0.
23 * 
24 *  
25 * Constraints:
26 * 
27 * 	1 <= k <= num.length <= 10^5
28 * 	num consists of only digits.
29 * 	num does not have any leading zeros except for the zero itself.
30 * 
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/remove-k-digits/
35// discuss: https://leetcode.com/problems/remove-k-digits/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40    pub fn remove_kdigits(num: String, k: i32) -> String {
41        String::new()
42    }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn test_402() {
53    }
54}
55


Back
© 2025 bowen.ge All Rights Reserved.