Class Solution
-
- All Implemented Interfaces:
public final class Solution
791 - Custom Sort String\.
Medium
You are given two strings order and s. All the words of
order
are unique and were sorted in some custom order previously.Permute the characters of
s
so that they match the order thatorder
was sorted. More specifically, if a characterx
occurs before a charactery
inorder
, thenx
should occur beforey
in the permuted string.Return any permutation of
s
that 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 <= 26
1 <= s.length <= 200
order
ands
consist of lowercase English letters.All the characters of
order
are unique.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final String
customSortString(String order, String s)
-
-
Method Detail
-
customSortString
final String customSortString(String order, String s)
-
-
-
-