205. Isomorphic Strings

Given two strings s and t, determine if they are isomorphic.
Two strings are isomorphic if the characters in s can be replaced to get t.

All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character but a character may map to itself.

For example,

Given "egg", "add", return true.
Given "foo", "bar", return false.
Given "paper", "title", return true.

Note:You may assume both s and t have the same length.

class Solution {
public:
    void feature(string &s, map >& m){
        for(int i=0;i v = vector();
                v.push_back(i);
                m[s[i]] = v;
            }else{
                m[s[i]].push_back(i);
            }
        }
    }
    
    bool compare(map >m, vector diff){
        for (std::map >::iterator it=m.begin(); it!=m.end(); ++it){
            vector &v = it->second;
            if(v.size() > 0){
                for(int i=1;i >ms = map >();
        map >mt = map >();
        vector diff = vector();
        
        feature(s, ms);
        feature(t, mt);
        for(int i=0;i

你可能感兴趣的:(205. Isomorphic Strings)