Simple C++ Solution Building FingerPrint


  • 0
    M
    class Solution {
    public:
        vector<int> FingerPrint(string const & s) {
            vector<int> fp(s.size());
            unordered_map<char, int> m;
            for (int i = 0; i < s.size(); ++i) {
                if (m.find(s[i]) == m.end()) m[s[i]] = m.size();
                fp[i] = m[s[i]];
            }
            return fp;
        }
        bool isIsomorphic(string s, string t) {
            return FingerPrint(s) == FingerPrint(t);
        }
    };
    

Log in to reply
 

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