题目描述

leetcode 205. Isomorphic Strings

ASCII码表中的控制字符和可显示字符共有128个,所以可以将string中出现的字符一次转换成数字就可比较大小。

即将两个string都转换成数字来比较大小

class Solution {
public:
    string replace(string s){
        char tmp[128] = {0};
        char ch = '0';
        for(int i = 0; i < s.length(); i++){
            if(tmp[s[i]] == 0){
                tmp[s[i]] = ++ch;
            }
            s[i] = tmp[s[i]];
        }
        return s;
    }
    
    bool isIsomorphic(string s, string t) {
        if(s.length() != t.length())
            return false;
        if(replace(s) == replace(t))
            return true;
        else
            return false;
        
    }

};

 

相关文章:

  • 2022-12-23
  • 2021-04-08
  • 2021-12-11
  • 2022-12-23
  • 2021-10-07
  • 2021-07-31
  • 2021-08-31
猜你喜欢
  • 2021-12-06
  • 2021-12-08
  • 2021-09-08
  • 2021-07-13
  • 2021-09-15
  • 2022-12-23
相关资源
相似解决方案