LCR 157 套餐内商品的排列顺序
某店铺将用于组成套餐的商品记作字符串 goods,其中 goods[i] 表示对应商品。请返回该套餐内所含商品的 全部排列方式 。
返回结果 无顺序要求,但不能含有重复的元素。
class Solution:
def goodsOrder(self, s: str) -> List[str]:
if not s: return
s=list(sorted(s))
res=[]
def helper(s,tmp):
if not s: res.append(''.join(tmp))
for i,char in enumerate(s):
if i>0 and s[i]==s[i-1]:
continue
helper(s[:i]+s[i+1:],tmp+[char])
helper(s,[])
return res