class Solution { public boolean isInterleave(String s1, String s2, String s3) { if(s1.length()+s2.length()!=s3.length()) return false; boolean [][] dp=new boolean[s1.length()+1][s3.length()+1]; dp[0][0]=true; for(int i=0;i<=s1.length();i++) for(int j=i;j<=s3.length();j++) { if(i>0&&s1.charAt(i-1)==s3.charAt(j-1)) dp[i][j]=dp[i-1][j-1]; int k=j-i; if(k<=s2.length()&&k>0&&s2.charAt(k-1)==s3.charAt(j-1)) dp[i][j]=dp[i][j]||dp[i][j-1]; } return dp[s1.length()][s3.length()]; } }