(self, ss)
| 28 | # 扩展习题, 生成字符的所有组合 |
| 29 | # 比如输入abc, 则他们的组合有['a', 'ab', 'abc', 'ac', 'b', 'bc', 'c'], ab和ba属于不同的排列, 但属于同一个组合 |
| 30 | def group(self, ss): |
| 31 | if not len(ss): |
| 32 | return [] |
| 33 | if len(ss) == 1: |
| 34 | return list(ss) |
| 35 | charList = list(ss) |
| 36 | charList.sort() |
| 37 | pStr = [] |
| 38 | for i in range(len(charList)): |
| 39 | pStr.append(charList[i]) |
| 40 | if i > 0 and charList[i] == charList[i - 1]: |
| 41 | continue |
| 42 | temp = self.group(''.join(charList[i + 1:])) |
| 43 | for j in temp: |
| 44 | pStr.append(charList[i] + j) |
| 45 | pStr = list(set(pStr)) |
| 46 | pStr.sort() |
| 47 | return pStr |
| 48 | |
| 49 | ss = 'acb' |
| 50 | S = Solution() |
no outgoing calls
no test coverage detected