코테준비 - Isomorphic Strings

정상화·2023년 2월 26일

LeetCode

목록 보기
175/222

Isomorphic Strings


class Solution {
public:
    bool isIsomorphic(string s, string t) {
        vector<char> sourceToDest(INT16_MAX, NULL);
        vector<char> destToSource(INT16_MAX, NULL);

        int strLen = s.length();
        for (int i = 0; i < strLen; i++) {
            char srcChar = s.at(i);
            char destChar = t.at(i);
            if (destToSource.at(destChar) == NULL) {
                if (sourceToDest.at(srcChar) == NULL) {
                    sourceToDest.at(srcChar) = destChar;
                    destToSource.at(destChar) = srcChar;
                } else {
                    return false;
                }
            } else if (destToSource.at(destChar) != srcChar) {
                return false;
            }
        }
        return true;
    }
};
profile
백엔드 희망

0개의 댓글