← 返回 meta 的题目列表Custom Order String Permutation Matching
类型:online_judge
meta
Given two strings, order and s. order has all unique letters and is sorted based on some custom order. Permute the characters in s to match the order defined by order. More specifically, if a character x appears before a character y in order, then x should also appear before y in the permuted string. Return any permutation of s that satisfies this condition.
Input:
order: a string containing unique letters.
s: a string.
Output: Return any permutation of s that matches the character order in order.
Example 1:
Input:
order = "cba", s = "abcd"
Output:
"cbad"
Example 2:
Input:
order = "cbafg", s = "abcd"
Output:
"cbad"
Requires linear time complexity.
Example
Input
cba
abcd