791. Custom Sort String Medium

@problem@discussion
#Hash Table#String#Sorting



1/**
2 * [791] Custom Sort String
3 *
4 * You are given two strings order and s. All the characters of order are unique and were sorted in some custom order previously.
5 * Permute the characters of s so that they match the order that order was sorted. More specifically, if a character x occurs before a character y in order, then x should occur before y in the permuted string.
6 * Return any permutation of s that satisfies this property.
7 *  
8 * Example 1:
9 * 
10 * Input: order = "cba", s = "abcd"
11 * Output: "cbad"
12 * Explanation: 
13 * "a", "b", "c" appear in order, so the order of "a", "b", "c" should be "c", "b", and "a". 
14 * Since "d" does not appear in order, it can be at any position in the returned string. "dcba", "cdba", "cbda" are also valid outputs.
15 * 
16 * Example 2:
17 * 
18 * Input: order = "cbafg", s = "abcd"
19 * Output: "cbad"
20 * 
21 *  
22 * Constraints:
23 * 
24 * 	1 <= order.length <= 26
25 * 	1 <= s.length <= 200
26 * 	order and s consist of lowercase English letters.
27 * 	All the characters of order are unique.
28 * 
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/custom-sort-string/
33// discuss: https://leetcode.com/problems/custom-sort-string/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38    pub fn custom_sort_string(order: String, s: String) -> String {
39        String::new()
40    }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48
49    #[test]
50    fn test_791() {
51    }
52}
53


Back
© 2025 bowen.ge All Rights Reserved.