using map&merg 2 string


  • 0
    W
    class Solution {
    public:
        bool isIsomorphic(string s, string t) {
            map<char,int>mymap;
            int i=0,size;
            size=s.size();
            if(size!=t.size()) return false;
            string tmp;
            tmp=s; s=s+t; t=t+tmp;
            for(auto c:s)
            {
                if(i==size) mymap.clear();
                if(mymap.count(c)<=0)  mymap[c]=i;
                else if(t[i]!=t[mymap[c]]) return false;
                ++i;
            }
            return true;
        }
    };
    

Log in to reply
 

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