【Java】【Python】【递归】判断两个字符串是否相同

public class h {
     
    public static boolean isSameString1(String s1,String s2){
     
        return s1.equals(s2);
    }
    public static boolean isSameString2(String s1,String s2){
     
        if(s1.length()!=s2.length()) return false;
        if(s1.length()==0) return true;

        if(s1.charAt(0) != s2.charAt(0)) return false;
        return isSameString2(s1.substring(1),s2.substring(1));

    }
    public static void main(String[] args){
     
        System.out.println(isSameString1("ReganYue","ReganUye"));
        System.out.println(isSameString1("ReganYue","ReganYue"));
        System.out.println(isSameString2("ReganYue","ReganUye"));
        System.out.println(isSameString2("ReganYue","ReganYue"));
    }
}
def isSameString(s1,s2):
    if(len(s1)!=len(s2)):
        return False;
    if(len(s1)==0):
        return True;
    if(s1[0]!=s2[0]):
        return False
    return isSameString(s1[1:],s2[1:])
def isSameString1(s1,s2):
    return (s1 == s2)

print(isSameString("Regan","rEGAN"))
print(isSameString("Regan","Regan"))
print(isSameString1("Regan","rEGAN"))
print(isSameString1("Regan","Regan"))

你可能感兴趣的:(java,蓝桥杯,python,java,字符串)