https://programmers.co.kr/learn/courses/30/lessons/12911
function solution(n) {
var answer = 0;
var target = n+1;
var strN = n.toString(2);
var countOne = strN.split('').filter(str=> str==='1').length;
while(target>n){
if(countOne === target.toString(2).split('').filter(str=> str==='1').length){
break;
}
target=target+1;
}
answer = target;
return answer;
}
while문 사용하기
혹시
while(target>n){
if(countOne === target.toString(2).split('').filter(str=> str==='1').length){
break;
}
target=target+1;
}
이부분을
while(target>n){
if(countOne === target.toString(2).split('').filter(str=> str==='1').length){
return target;
}
target=target+1;
}
이렇게 바꿔도 돌아가는데 같은 의미 일까요??