Split String – Python 3 (Week 19 – 01)

class Solution:
    """
    @param: : a string to be split
    @return: all possible split string array
    """

    def splitString(self, s):
        # write your code here
        result = []
        self.dfs(s, [], result)
        return result
        

    def dfs(self, s, path, result):
        if s == '':
            result.append(path[:])
            return
        for i in range(2):
            if i + 1 <= len(s):
                path.append(s[:i+1])
                self.dfs(s[i+1:], path, result)
                path.pop()

Leave a comment

Design a site like this with WordPress.com
Get started