942. DI String Match Easy

@problem@discussion
#Array#Two Pointers#String#Greedy



1/**
2 * [942] DI String Match
3 *
4 * A permutation perm of n + 1 integers of all the integers in the range [0, n] can be represented as a string s of length n where:
5 * 
6 * 	s[i] == 'I' if perm[i] < perm[i + 1], and
7 * 	s[i] == 'D' if perm[i] > perm[i + 1].
8 * 
9 * Given a string s, reconstruct the permutation perm and return it. If there are multiple valid permutations perm, return any of them.
10 *  
11 * Example 1:
12 * Input: s = "IDID"
13 * Output: [0,4,1,3,2]
14 * Example 2:
15 * Input: s = "III"
16 * Output: [0,1,2,3]
17 * Example 3:
18 * Input: s = "DDI"
19 * Output: [3,2,0,1]
20 *  
21 * Constraints:
22 * 
23 * 	1 <= s.length <= 10^5
24 * 	s[i] is either 'I' or 'D'.
25 * 
26 */
27pub struct Solution {}
28
29// problem: https://leetcode.com/problems/di-string-match/
30// discuss: https://leetcode.com/problems/di-string-match/discuss/?currentPage=1&orderBy=most_votes&query=
31
32// submission codes start here
33
34impl Solution {
35    pub fn di_string_match(s: String) -> Vec<i32> {
36        vec![]
37    }
38}
39
40// submission codes end
41
42#[cfg(test)]
43mod tests {
44    use super::*;
45
46    #[test]
47    fn test_942() {
48    }
49}
50


Back
© 2025 bowen.ge All Rights Reserved.