题目链接: https://leetcode-cn.com/problems/zi-fu-chuan-de-pai-lie-lcof/

题目

输入一个字符串,打印出该字符串中字符的所有排列。
你可以以任意顺序返回这个字符串数组,但里面不能有重复元素
示例:

  1. 输入:s = "abc"
  2. 输出:["abc","acb","bac","bca","cab","cba"]

Python

偷懒解法

偷懒解法对锻炼 Python 熟悉度还是有一点意义的。

import itertools

class Solution:
    def permutation(self, s: str) -> List[str]:
        return list(set(map("".join, itertools.permutations(s, len(s)))))

正式解法

C++

Rust