Java - 7ms - Array


  • 0
    N
    public class Solution {
        public boolean isIsomorphic(String s, String t) {
            if(s == null || t == null || s.length() != t.length()) return false;
            
            int[] sI = new int[128];
            int[] tI = new int[128];
            
            for (int i=0; i < s.length(); i++) {
                
                int sc = s.charAt(i);
                int tc = t.charAt(i);
                
                if (sI[sc] != tI[tc]) return false;
                sI[sc] = tI[tc] = i + 1;
            }
            return true;
            
        }
    }
    

Log in to reply
 

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