javapackage com.spring;
public class IsomorphicStrings {
     public boolean isIsomorphic(String s, String t) {
         boolean  flag=true;
        int n=s.length()-1;
    for(int i=0;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(s.charAt(i)==s.charAt(j)){           
                if(t.charAt(i)==t.charAt(j))
                    flag=true;
                else{
                    flag=false;
                    break;
                }
            }
            if(s.charAt(i)!=s.charAt(j)){
                if(t.charAt(i)!=t.charAt(j))
                    flag=true;
                else{                   
                    flag=false;
                    break;
                }
            }

        }
        if(!flag){
            return  flag;
        }

    }

    return flag;     
        }
  public static void main(String[] args) {
    System.out.println(new IsomorphicStrings().isIsomorphic("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqr", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ abcdefghijklmnopqr"));

}
}

结果运行超时了。报出了Time Limit Exceeded异常。


happyfish
2.4k 声望66 粉丝

[链接]