Skip to content

Latest commit

 

History

History
30 lines (26 loc) · 783 Bytes

680.-split-string.md

File metadata and controls

30 lines (26 loc) · 783 Bytes

680. Split String

class Solution:
    """
    @param: : a string to be split
    @return: all possible split string array
    """
    def splitString(self, s):
        # write your code here
        ans = []
        seq = []
        if not s:
            ans.append(seq)
            return ans
        ## 第一感觉这是dp 一步两步
        ## 发现不会 ,那就搜索DFS吧
 
        def helper(idx,seq=[]):
            if idx == len(s):
                ans.append(seq)
                return    # 终止条件
            
            for i in range(1,3): ## 只能取 1 或 2
                if idx + i <= len(s): ## 区间右开
                    helper(idx+i,seq + [s[idx:idx+i]]) ## 确保seq 本身没被修改
        helper(0)
        return ans