Skip to content

Commit fc871f0

Browse files
authored
Create split_string.py
1 parent e780019 commit fc871f0

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

split_string.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)