@@ -0,0 +1,1731 @@
+package leetcode;%0A%0Aimport java.util.HashSet;%0Aimport java.util.List;%0Aimport java.util.Set;%0A%0Apublic class Task139 %7B%0A%0A    public static void main(String%5B%5D args) %7B%0A        System.out.println(new Task139().wordBreak(%22leetcode%22, List.of(%22leet%22, %22code%22)));%0A        System.out.println(new Task139().wordBreak(%22applepenapple%22, List.of(%22apple%22, %22pen%22)));%0A        System.out.println(new Task139().wordBreak(%22catsandog%22, List.of(%22cats%22, %22dog%22, %22sand%22, %22and%22, %22cat%22)));%0A        System.out.println(new Task139().wordBreak(%22cars%22, List.of(%22car%22, %22ca%22, %22rs%22)));%0A        System.out.println(new Task139().wordBreak(%22aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab%22, List.of(%22a%22, %22aa%22, %22aaa%22, %22aaaa%22, %22aaaaa%22, %22aaaaaa%22, %22aaaaaaa%22, %22aaaaaaaa%22, %22aaaaaaaaa%22, %22aaaaaaaaaa%22)));%0A    %7D%0A%0A    private final Set%3CInteger%3E visited = new HashSet%3C%3E();%0A%0A    public boolean wordBreak(String s, List%3CString%3E wordDict) %7B%0A        return wordBreak0(s, 0, wordDict);%0A    %7D%0A%0A    private boolean wordBreak0(String s, int index, List%3CString%3E wordDict) %7B%0A        if (visited.contains(index)) %7B%0A            return false;%0A        %7D%0A        if (index %3E= s.length()) %7B%0A            return true;%0A        %7D%0A        String substring = s.substring(index);%0A        for (int i = 0; i %3C wordDict.size(); i++) %7B%0A            String word = wordDict.get(i);%0A            if (substring.startsWith(word)) %7B%0A                boolean success = wordBreak0(s, index + word.length(), wordDict);%0A                if (success) %7B%0A                    return true;%0A                %7D else %7B%0A                    visited.add(index);%0A                %7D%0A            %7D%0A        %7D%0A        return false;%0A    %7D%0A%7D%0A

Add Task139