29

来源:互联网 发布:twrp备份文件提取数据 编辑:程序博客网 时间:2024/05/01 20:27

2017.9.14

就暴力一点,一个字符一个字符的比较吧。

public class Solution {    /*     * @param s1: A string     * @param s2: A string     * @param s3: A string     * @return: Determine whether s3 is formed by interleaving of s1 and s2     */    public boolean isInterleave(String s1, String s2, String s3) {        // write your code here    int l1 = s1.length();    int l2 = s2.length();    int l3 = s3.length();    if(l3 != l1 + l2){    return false;    }    if(l1 == 0 && l1 == l2 && l2== l3){    return true;    }    if(l1 > 0 && s3.charAt(0) == s1.charAt(0)){    boolean res = isInterleave(s1.substring(1), s2, s3.substring(1));    if(res == true){    return res;    }    }    if(l2 > 0 && s3.charAt(0) == s2.charAt(0)){    boolean res = isInterleave(s1, s2.substring(1), s3.substring(1));    if(res == true){    return res;    }    }    return false;    }}


原创粉丝点击