Clean and simple java solution


  • -2
    S

    public class Solution {
    public boolean wordBreak(String s, Set<String> dict) {
    boolean[] d = new boolean[s.length() + 1];
    d[0] = true;
    for (int i = 1; i <= s.length(); ++i) {
    for (int j = 0; j < i; ++j) {
    d[i] |= d[j] && dict.contains(s.substring(j, i));
    }
    }
    return d[s.length()];
    }
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.