3216. Lexicographically Smallest String After a Swap Easy

@problem@discussion
#String#Greedy



1/**
2 * [3216] Lexicographically Smallest String After a Swap
3 *
4 * Given a string s containing only digits, return the <span data-keyword="lexicographically-smaller-string">lexicographically smallest string</span> that can be obtained after swapping adjacent digits in s with the same parity at most once.
5 * Digits have the same parity if both are odd or both are even. For example, 5 and 9, as well as 2 and 4, have the same parity, while 6 and 9 do not.
6 *  
7 * <strong class="example">Example 1:
8 * <div class="example-block">
9 * Input: <span class="example-io">s = "45320"</span>
10 * Output: <span class="example-io">"43520"</span>
11 * Explanation: 
12 * s[1] == '5' and s[2] == '3' both have the same parity, and swapping them results in the lexicographically smallest string.
13 * </div>
14 * <strong class="example">Example 2:
15 * <div class="example-block">
16 * Input: <span class="example-io">s = "001"</span>
17 * Output: <span class="example-io">"001"</span>
18 * Explanation:
19 * There is no need to perform a swap because s is already the lexicographically smallest.
20 * </div>
21 *  
22 * Constraints:
23 * 
24 * 	2 <= s.length <= 100
25 * 	s consists only of digits.
26 * 
27 */
28pub struct Solution {}
29
30// problem: https://leetcode.com/problems/lexicographically-smallest-string-after-a-swap/
31// discuss: https://leetcode.com/problems/lexicographically-smallest-string-after-a-swap/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35impl Solution {
36    pub fn get_smallest_string(s: String) -> String {
37        String::new()
38    }
39}
40
41// submission codes end
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_3216() {
49    }
50}
51


Back
© 2025 bowen.ge All Rights Reserved.