We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e780019 commit fc871f0Copy full SHA for fc871f0
split_string.py
@@ -0,0 +1,27 @@
1
+# coding: utf-8
2
+
3
+class Solution:
4
+ """
5
+ @param: : a string to be split
6
+ @return: all possible split string array
7
8
9
+ def splitString(self, s):
10
+ # write your code here
11
+ result = []
12
+ Solution._split(s, 0, [], result)
13
+ return result
14
15
+ @staticmethod
16
+ def _split(s, start, tmp, result):
17
+ if start >= len(s):
18
+ result.append(tmp)
19
+ return
20
+ tmp_ = tmp[:]
21
+ tmp_.append(s[start]) # 追加一个字符
22
+ Solution._split(s, start + 1, tmp_, result)
23
+ if start + 2 <= len(s):
24
+ tmp.append(s[start:start + 2]) # 追加两个字符
25
+ Solution._split(s, start + 2, tmp, result)
26
27
+# easy: http://lintcode.com/zh-cn/problem/split-string/
0 commit comments