Easy to understand C++ solution

  • 0

    class Solution {
    bool isIsomorphic(string s, string t) {
    if(s.length()!=t.length()) return false;
    int n = s.length();
    int check_s[128]={0};
    for(int i=0;i<n;i++)
    if(check_s[s[i]]==0) check_s[s[i]]=t[i];
    else if(check_s[s[i]]!=t[i]) return false;
    int check_t[128]={0};
    for(int i=0;i<n;i++)
    if(check_t[t[i]]==0) check_t[t[i]]=s[i];
    else if(check_t[t[i]]!=s[i]) return false;
    return true;

Log in to reply

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