[Algorithm] 32 week(9.05 ~ 9.11) 1/3

Dev_min·2022년 9월 5일
0

algorithm

목록 보기
105/157

205. Isomorphic Strings

var isIsomorphic = function(s, t) {
    const sMap = new Map();
    const tMap = new Map();
    
    let sCount = 0, tCount = 0;
    
    for(let i = 0; i < s.length; i++){
        const charS = s.charAt(i);
        const charT = t.charAt(i);
        
        if(!sMap.has(charS)){ 
            sMap.set(charS,sCount); 
            sCount++;
        }
        
        if(!tMap.has(charT)){ 
            tMap.set(charT,tCount); 
            tCount++;
        }
        
        if(sMap.get(charS) !== tMap.get(charT)) return false;
    }
    
    return true;
};
profile
TIL record

0개의 댓글