Class Solution
- java.lang.Object
-
- g0701_0800.s0791_custom_sort_string.Solution
-
public class Solution extends Object
791 - Custom Sort String.Medium
You are given two strings order and s. All the words of
orderare unique and were sorted in some custom order previously.Permute the characters of
sso that they match the order thatorderwas sorted. More specifically, if a characterxoccurs before a characteryinorder, thenxshould occur beforeyin the permuted string.Return any permutation of
sthat satisfies this property.Example 1:
Input: order = “cba”, s = “abcd”
Output: “cbad”
Explanation: “a”, “b”, “c” appear in order, so the order of “a”, “b”, “c” should be “c”, “b”, and “a”. Since “d” does not appear in order, it can be at any position in the returned string. “dcba”, “cdba”, “cbda” are also valid outputs.
Example 2:
Input: order = “cbafg”, s = “abcd”
Output: “cbad”
Constraints:
1 <= order.length <= 261 <= s.length <= 200orderandsconsist of lowercase English letters.- All the characters of
orderare unique.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-