728x90
반응형
문제
https://school.programmers.co.kr/learn/courses/30/lessons/70129
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
풀이
class Solution {
public int[] solution(String s) {
int[] answer = {0,0};
while(!s.equals("1")) {
int temp = s.length();
s = s.replaceAll("0", "");
answer[0]++;
answer[1] += temp - s.length();
s = Integer.toBinaryString(s.length());
}
return answer;
}
}
1. "1" 될 떄 까지 반복
2. 10진수 -> 2진수 변환 Integer.toBinaryString()
h-algorithm/프로그래머스/2/70129. 이진 변환 반복하기 at master · yhyuk/h-algorithm
This is an auto push repository for Baekjoon Online Judge created with [BaekjoonHub](https://github.com/BaekjoonHub/BaekjoonHub). - yhyuk/h-algorithm
github.com
728x90
반응형
'알고리즘 > Java' 카테고리의 다른 글
프로그래머스 코딩테스트 Level 2. 멀리뛰기 with Java (0) | 2024.09.20 |
---|---|
프로그래머스 코딩테스트 Level 2. 구명보트 with Java (0) | 2024.09.20 |
프로그래머스 코딩테스트 Level 2. 피보나치 수 with Java (1) | 2024.09.17 |
프로그래머스 코딩테스트 Level 2. 다음 큰 숫자 with Java (0) | 2024.09.12 |
프로그래머스 코딩테스트 Level 2. 숫자의 표현 with Java (2) | 2024.09.11 |
댓글