要求,不开辟新的数组内存
public static boolean isSuffix(String suffix ,String str){ if (str.length()<suffix.length()){ return false; } for (int i = 0;i<suffix.length();i++){ char item = suffix.charAt(suffix.length()-1-i); if (item==str.charAt(str.length()-1-i)){ continue; } else { return false; } } return true; }思路如下,如果str长度小于suffix,自然suffix不是其后缀
然后依次拿suffix从后往前和str从后往前的字符来对比,如果一致,
则继续对比,最后能够把for循环走完,则证明是其后缀