题目:
输入一个长度为n的字符串,输出该字符串中字符的所有组合
(如果输入"abc",它的组合有a、b、c、ab、ac、bc、abc。 ab与ba算一种组合)
思路:
class Solution:
l = []
def com(self,s):
out = []
if len(s) == 0:
return
a = len(s)
for i in range(1, a+1):
self.combation(s, 0, i, out)
def combation(self,s ,begin, length, out):
if length == 0:
print(out)
return
if begin == len(s):
return
out.append(s[begin])
self.combation(s, begin+1, length-1, out)
out.pop()
self.combation(s, begin+1, length, out)
##测试如下
c = Solution()
b = c.com("abc")