If t is the subString of s

来源:互联网 发布:windows主辅域搭建 编辑:程序博客网 时间:2024/06/06 02:19
    //judge if t is the substring of s    public boolean isSubString(String s, String t){        if(s == null || t == null) return false;        if(t.length() == 0) return true;        int index = 0;        int lengthS = s.length();        int lengthT = t.length();        while(index <= lengthS - lengthT) {            if(s.charAt(index) == t.charAt(0)) {                int tmp = index;                while(tmp - index < lengthT && s.charAt(tmp) == t.charAt(tmp - index)) {                    tmp++;                }                if(tmp - index == lengthT) return true;            }            index++;        }        return false;    }