✅ LV. 2
s
에서 1
의 개수를 countvoid f(int n) {
if(n > 1) f(n/2);
pritf(%d, n%2);
}
그냥 암기하는 편이 맘 편하다,,
#include <string>
#include <vector>
using namespace std;
string str="";
void f(int n) {
if(n > 1) f(n/2);
str+=to_string(n%2);
}
vector<int> solution(string s) {
int z=0, r=0;
vector<int> answer;
while (1) {
if(s=="1") break;
int cnt=0;
for(int i=0;i<s.size();i++) {
if(s[i]=='1') cnt++;
else z++;
}
r++;
f(cnt);
s=str;
str="";
}
answer.push_back(r);
answer.push_back(z);
return answer;
}