Inflearn Community Q&A
후보가 다섯명이어서 직접 오브젝트를 생성했습니다.
Written on
·
316
0
function solution (str){
let cnt = {
'A':0,
'B':0,
'C':0,
'D':0,
'E':0,
}
for(let i=0; i<str.length ;i++){
if(str[i] === 'A') cnt['A']++;
else if(str[i] === 'B') cnt['B']++;
else if(str[i] === 'C') cnt['C']++;
else if(str[i] === 'D') cnt['D']++;
else cnt['E']++;
}
const sortable = Object.fromEntries(Object.entries(cnt).sort(([,a],[,b]) => b-a));
return Object.keys(sortable)[0];
}
안녕하세요. map 개념을 잘 몰라서 오브젝트 직접 생성해서 정렬하고 답을 구했습니다.
1. 이 경우 시간복잡도는 O(n)이 맞을까요?
2. 다른 해쉬 문제에서도 이렇게 해도 괜찮을까요? (여기서는 후보가 다섯명뿐이라 쉽게 구현했지만.. 수가 많아지면 힘들어질까요..??)
좋은 강의 감사합니다.
javascript코테 준비 같이 해요!
Quiz
45% of people got it wrong. Give it a try!
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?
Answer 2
1
0





