Created
April 25, 2018 09:03
-
-
Save zcwang/ab7461351317fa899f46b27587e3ea80 to your computer and use it in GitHub Desktop.
Leetcode's Word Break-I
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public boolean wordBreak(String s, List<String> wordDict) { | |
boolean[] mem = new boolean[s.length() + 1]; | |
mem[0] = true; | |
for (int i = 1; i <= s.length(); i++) { | |
for (int k = 0; k < i; k++) { | |
if (mem[k] && wordDict.contains(s.substring(k, i))) { | |
mem[i] = true; | |
break; | |
} | |
} | |
} | |
return mem[s.length()]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment