My Solution beats 90% of the solutions


  • 0
    A
    public class Solution {
        public boolean isIsomorphic(String s, String t) {
            Map<Character, Character> map = new HashMap<>();
            char[] sc = new char[256];
            char[] tc = new char[256];
            for(int i = 0; i < s.length(); i++){
                char schar = s.charAt(i);
                char tchar = t.charAt(i);
                if(sc[schar - 0] == 0 && tc[tchar - 0] == 0){
                    sc[schar - 0] = tchar;
                    tc[tchar - 0] = schar;
                    
                } else {
                      
                      if( sc[schar - 0] != tchar || tc[tchar - 0] != schar) return false; 
                }
            }
            
            return true;
    }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.