Share my Java solution beats 90%+ may help u


  • 0
    public class Solution {
        public boolean isIsomorphic(String s, String t) {
    		int[] times1 = new int[128], times2 = new int[128];
    		int len = s.length();
    		for (int i = 0, smax = 0, tmax = 0; i < len; ++i) {
    			char sc = s.charAt(i);
    			char tc = t.charAt(i);
    			if (times1[sc] == 0) {
    				times1[sc] = ++smax;
    			}
    			if (times2[tc] == 0) {
    				times2[tc] = ++tmax;
    			}
    			if (times1[sc] != times2[tc])
    				return false;
    		}
    		return true;
    	}
    }

  • 0
    N
    This post is deleted!

  • 0
    N

    the naming of "times" is too bad, it is really confusing. In fact, it is just a char to symbol mapping.


Log in to reply
 

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