LeetCode 205. Isomorphic Strings

Zoka
·
·
IPFS
·
class Solution {
    
    public boolean isIsomorphic(String s, String t) {
        
        if(s.length()!=t.length()){
            return false;
        }
        
        char[] sChar = new char[256];
        char[] tChar = new char[256];
        
        for(int i=0; i<s.length(); i++){
            
            char sc = s.charAt(i);
            char tc = t.charAt(i);
            
            if(sChar[sc] == 0 && tChar[tc] == 0){
                sChar[sc] = tc;
                tChar[tc] = sc;
            }else if(sChar[sc] != tc){
                return false;
            }
            System.out.println(sc);
            System.out.println(tc);
            
        }
        return true;
    }
}


CC BY-NC-ND 2.0 授权

喜欢我的作品吗?别忘了给予支持与赞赏,让我知道在创作的路上有你陪伴,一起延续这份热忱!