public boolean wordBreak(final String s, final Set<String> wordDict) {

        if (s == null || wordDict.size() <= 0) {
            return false;
        }

        final int length = s.length();
        final boolean[] seg = new boolean[length + 1];
        // initialize
        seg[0] = true;
        for (int i = 1; i <= length; i++) {
            // i>j>=0
            for (int j = 0; j < i; j++) {
                if (seg[j] && wordDict.contains(s.substring(j, i))) {
                    seg[i] = true;
                    continue;
                }

            }
        }

        return seg[length];
    }