프로그래머스_C#/Level_2
[프로그래머스 C#] 이진 변환 반복하기
최애뎡
2021. 11. 14. 00:33
728x90
반응형
https://programmers.co.kr/learn/courses/30/lessons/70129
코딩테스트 연습 - 이진 변환 반복하기
programmers.co.kr
using System;
using System.Linq;
public class Solution
{
public int[] solution(string s)
{
int[] answer = new int[2];
while (s != "1")
{
answer[0] += 1;
int oldLength = s.Length;
int temp = s.ToList().RemoveAll(x => x == '0');
answer[1] += temp;
s = Convert.ToString(oldLength - temp, 2);
}
return answer;
}
}
s == "1" 이 아니면 계속 돌리고 한번 돌릴 때마다 ++
0 다 지우고 남은 길이 2진수 변환
반응형