private void helper(final String s, final Set<String> wordDict, final int loc, final String currentStr, final List<String> res) {

        if (loc == s.length()) {
            res.add(currentStr);
            return;
        }

        final StringBuilder str = new StringBuilder();
        // loop and a recursive to get all possible results
        for (int i = loc; i < s.length(); i++) {
            str.append(s.charAt(i));
            // save a current result, then recursively handle the rest of the string
            if (wordDict.contains(str.toString())) {
                final String newString = currentStr.length() > 0 ? (currentStr + " " + str.toString()) : str.toString();
                helper(s, wordDict, i + 1, newString, res);
            }
        }
    }