public boolean isInterleave(String s1, String s2, String s3) {
        if (s1.length() + s2.length() != s3.length()) {
            return false;
        }

        boolean[] m = new boolean[s1.length() + 1];
        m[0] = true;
        for (int i = 1; i <= s1.length(); i++) {
            m[i] = m[i - 1] && s3.charAt(i - 1) == s1.charAt(i - 1);
        }

        for (int i = 1; i <= s2.length(); i++) {
            m[0] = m[0] && s3.charAt(i - 1) == s2.charAt(i - 1);
            for (int j = 1; j <= s1.length(); j++) {
                m[j] = (m[j - 1] && s1.charAt(j - 1) == s3.charAt(i + j - 1))
                        || (m[j] && s2.charAt(i - 1) == s3.charAt(i + j - 1));
            }
        }
        return m[s1.length()];
    }