Simple 8ms solution in cpp


  • 0
    L
    class Solution {
    public:
        bool isIsomorphic(string s, string t) {
            return baseIso(s) == baseIso(t);
        }
        string baseIso(string str) {
            char m[256] = {0};
            string ret;
            int k = 1;
            for(int i = 0; i < str.length(); i++) {
                if (m[str[i]] == 0) {
                    m[str[i]] = k;
                    ret += k - 1;
                    k++;
                }
                else {
                    ret += m[str[i]] - 1;
                }
            }
            return ret;
        }
    };

Log in to reply
 

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