[프로그래머스] 70129 이진 변환 반복하기 / Java 정답

programmers

쉬운 문제라도 문제를 푸는 방법은 다양합니다.

더 명확하고 깔끔한 문제 해결 방법을 아신다면 자유롭게 말씀해주세요.

프로그래머스 701529 이진 변환 반복하기

프로그래머스 저작권을 침해하지 않기 위해

문제 보시고 싶으시면 버튼을 눌러주세요.

답변 형식
프로그래머스 70129 자바
프로그래머스 70129 파이썬

이진법으로 표현 된 문자열 S가 “10”이 되기 위해 특정 규칙을 몇 번 반복해야하는지, 그 과정을 통해 제거된 0의 갯수를 반환한다.

풀이 조건

문자열의 모든 0을 제거하고

제거하고 남은 1들의 갯수를 다시 2진법으로 변환하는 과정을 반복하면 된다.

 

함수의 활용이 궁금하다면 아래 JAVA 정답 해설을 참조하시면 좋을 것 같다.

    class Solution {
        public int[] solution(String s) {
            int del = 0;
            int cnt = 0;
            while(true) {
                cnt++;
                String s_now = s.replaceAll(“0”, “”);
                del += s.length()-s_now.length();
                if(s_now.equals(“1”)) break;
                s = Integer.toBinaryString(s_now.length());            
            }
           
            int[] answer = {cnt, del};
            return answer;
        }
    }
class Solution {
    public int[] solution(String s) {

        int del = 0; // 0 삭제 횟수
        int cnt = 0; // 규칙 반복 횟수

        while(true) {
            cnt++;
            // 반복 횟수 +1

            String s_now = s.replaceAll(“0”, “”);
            // x의 모든 0을 제거합니다.

            del += s.length()-s_now.length();
            // 삭제한 0 갯수 세기

            if(s_now.equals(“1”)) break;
            // s가 “1”이 되어 결과값 반환

            s = Integer.toBinaryString(s_now.length());  
            // x의 길이를 c라고 하면, x를 “c를 2진법으로 표현한 문자열”로 바꿉니다.  
        }
       
        int[] answer = {cnt, del};
        return answer;
    }
}

“[프로그래머스] 70129 이진 변환 반복하기 / Java 정답”의 79개의 댓글

  1. [6530]ar66 Official Login | Trusted Online Casino Malaysia Fast Payout,ar66 offers a premium gaming experience with an easy app download and a wide selection of online slots. Enjoy secure play and rapid withdrawals. Join us today! visit: ar66

  2. I have been playing online for years and this one really stands out for its clean interface and fair gameplay. The live dealer games run without any lag and the payout speed is honestly amazing. I appreciate how transparent they are with their terms. Definitely my go to site now. mu889

  3. This place has such a vibrant atmosphere and I enjoy every session I spend here. The game selection is impressive and the payout times are always on point. It really feels like a community built around genuine enjoyment. incricaza

  4. Finally found a spot that does not waste my time with complicated verification steps. The welcome bonus came in clearly and the game library has exactly what I look for after work. Customer care actually listens and solves issues on the first call. bdbajji99

  5. Trust me when I say rajabotaklink is the hidden gem we all needed. The community here is so welcoming and the games are tested for fairness. I finally found a spot where I can relax and enjoy every spin without worrying about a thing. rajabotaklink

  6. Playing on citycenterrosarioonline feels like having a VIP lounge right in my living room. The live dealer options are top notch and the chat feature lets me connect with other players without any lag. I have been testing different slots and the payout frequency keeps me coming back. It is refreshing to find a site that actually cares about player comfort and fair play. citycenterrosarioonline

  7. [8166]7u7bet অফিসিয়াল লগইন | অনলাইন স্লট ও বিকাশ পেমেন্ট সুবিধা,7u7bet অ্যাপ ডাউনলোড করে লাইভ ক্যাসিনো বোনাস এবং সেরা অনলাইন স্লট গেম উপভোগ করুন। বিকাশ পেমেন্ট সুবিধার মাধ্যমে দ্রুত লেনদেন করতে আজই যোগ দিন। visit: 7u7bet

  8. [4981]suhu189 | Login Resmi Link Alternatif Situs Slot Gacor Hari Ini,suhu189 menyediakan akses login resmi dan link alternatif terbaru. Nikmati judi casino online terpercaya dengan kemudahan deposit via dana. Daftar sekarang juga! visit: suhu189

댓글 달기

이메일 주소는 공개되지 않습니다.