2384. Largest Palindromic Number Medium

@problem@discussion
#Hash Table#String#Greedy



1/**
2 * [2384] Largest Palindromic Number
3 *
4 * You are given a string num consisting of digits only.
5 * Return the largest palindromic integer (in the form of a string) that can be formed using digits taken from num. It should not contain leading zeroes.
6 * Notes:
7 * 
8 * 	You do not need to use all the digits of num, but you must use at least one digit.
9 * 	The digits can be reordered.
10 * 
11 *  
12 * Example 1:
13 * 
14 * Input: num = "444947137"
15 * Output: "7449447"
16 * Explanation: 
17 * Use the digits "4449477" from "<u>44494</u><u>7</u>13<u>7</u>" to form the palindromic integer "7449447".
18 * It can be shown that "7449447" is the largest palindromic integer that can be formed.
19 * 
20 * Example 2:
21 * 
22 * Input: num = "00009"
23 * Output: "9"
24 * Explanation: 
25 * It can be shown that "9" is the largest palindromic integer that can be formed.
26 * Note that the integer returned should not contain leading zeroes.
27 * 
28 *  
29 * Constraints:
30 * 
31 * 	1 <= num.length <= 10^5
32 * 	num consists of digits.
33 * 
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/largest-palindromic-number/
38// discuss: https://leetcode.com/problems/largest-palindromic-number/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43    pub fn largest_palindromic(num: String) -> String {
44        String::new()
45    }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn test_2384() {
56    }
57}
58


Back
© 2025 bowen.ge All Rights Reserved.