Skip to content

Instantly share code, notes, and snippets.

@zcwang
Created April 25, 2018 09:03
Show Gist options
  • Save zcwang/ab7461351317fa899f46b27587e3ea80 to your computer and use it in GitHub Desktop.
Save zcwang/ab7461351317fa899f46b27587e3ea80 to your computer and use it in GitHub Desktop.
Leetcode's Word Break-I
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