[Solution]205. Isomorphic Strings

·

1 min read

Problem

Problem_Link

Solutions (time, space)

O(n), O(n) length of String

class Solution{
    public boolean isIsomorphic(String s, String t) {
        int[] chkList = new int[256];

        for (int i = s.length() - 1; i > -1; --i) {
            if (chkList[s.charAt(i)] != chkList[t.charAt(i) + 128]) return false;

            chkList[s.charAt(i)] = i;
            chkList[t.charAt(i) + 128] = i;
        }

        return true;
    }

Explanation

  • using Hashmap or array to contain the data and compare

  • Since Strings(ASCII code) are limited, we can use array instead of HashMap