인프런 커뮤니티 질문&답변
혹시 강사님 이 풀이는 효율적이지 못할까요?
작성
·
260
0
function solution(s1,s2) {
let answer = 'YES';
console.log(s1,s2)
let map1 = new Map();
for(let s of s1) {
if(map1.has(s)) map1.set(s, map1.get(s)+1);
else map1.set(s,1);
}
let map2 = new Map();
for(let s of s2) {
if(map2.has(s)) map2.set(s, map2.get(s)+1);
else map2.set(s,1);
}
for(let s of s1) {
if(map1.get(s) !== map2.get(s)) answer = 'NO'; break;
}
return answer;
}
let str1 = 'abaCC';
let str2 = 'Caaab';
console.log(solution(str1,str2))
퀴즈
What is the main reason why two-pointer or sliding window techniques are more efficient than nested loops?
Because it uses less memory?
Is it because the code is shorter?
Is it because it achieves O(N) time complexity in most cases?
Is it because it's not affected by the input data size?





