670. Maximum Swap Medium

@problem@discussion
#Math#Greedy



1/**
2 * [670] Maximum Swap
3 *
4 * You are given an integer num. You can swap two digits at most once to get the maximum valued number.
5 * Return the maximum valued number you can get.
6 *  
7 * Example 1:
8 * 
9 * Input: num = 2736
10 * Output: 7236
11 * Explanation: Swap the number 2 and the number 7.
12 * 
13 * Example 2:
14 * 
15 * Input: num = 9973
16 * Output: 9973
17 * Explanation: No swap.
18 * 
19 *  
20 * Constraints:
21 * 
22 * 	0 <= num <= 10^8
23 * 
24 */
25pub struct Solution {}
26
27// problem: https://leetcode.com/problems/maximum-swap/
28// discuss: https://leetcode.com/problems/maximum-swap/discuss/?currentPage=1&orderBy=most_votes&query=
29
30// submission codes start here
31
32impl Solution {
33    pub fn maximum_swap(num: i32) -> i32 {
34        0
35    }
36}
37
38// submission codes end
39
40#[cfg(test)]
41mod tests {
42    use super::*;
43
44    #[test]
45    fn test_670() {
46    }
47}
48


Back
© 2025 bowen.ge All Rights Reserved.