题目

791. Custom Sort String Medium
规则:
S和T是由小写字母组成的字符串。在S中,没有字母出现超过一次。
S之前是按照自定义顺序排序的。
我们要对T的字符进行排序,使它们与S排序的顺序相匹配。
更具体地说,如果x出现在S中的y之前,那么x应该出现在返回字符串中的y之前。
返回任何满足此属性的T排列(作为字符串)。

代码

def customSortString(self, S, T):
        """
        :type S: str
        :type T: str
        :rtype: str
        """
        l = []
        for i in S:
                l.append(i*T.count(i))
        for i in T:
            if i not in S:
                l.append(i)
        return ''.join(l)

相关文章:

  • 2022-12-23
  • 2021-06-15
  • 2022-01-05
  • 2021-09-30
  • 2021-08-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-25
  • 2021-06-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-13
  • 2022-03-02
相关资源
相似解决方案