1417. Reformat The String Easy
1/**
2 * [1417] Reformat The String
3 *
4 * You are given an alphanumeric string s. (Alphanumeric string is a string consisting of lowercase English letters and digits).
5 * You have to find a permutation of the string where no letter is followed by another letter and no digit is followed by another digit. That is, no two adjacent characters have the same type.
6 * Return the reformatted string or return an empty string if it is impossible to reformat the string.
7 *
8 * Example 1:
9 *
10 * Input: s = "a0b1c2"
11 * Output: "0a1b2c"
12 * Explanation: No two adjacent characters have the same type in "0a1b2c". "a0b1c2", "0a1b2c", "0c2a1b" are also valid permutations.
13 *
14 * Example 2:
15 *
16 * Input: s = "leetcode"
17 * Output: ""
18 * Explanation: "leetcode" has only characters so we cannot separate them by digits.
19 *
20 * Example 3:
21 *
22 * Input: s = "1229857369"
23 * Output: ""
24 * Explanation: "1229857369" has only digits so we cannot separate them by characters.
25 *
26 *
27 * Constraints:
28 *
29 * 1 <= s.length <= 500
30 * s consists of only lowercase English letters and/or digits.
31 *
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/reformat-the-string/
36// discuss: https://leetcode.com/problems/reformat-the-string/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41 pub fn reformat(s: String) -> String {
42 String::new()
43 }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_1417() {
54 }
55}
56
Back
© 2025 bowen.ge All Rights Reserved.