[프로그래머스] 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. [url=https://raskrutka-sajtov-zakazat.ru]Раскрутка сайтов заказать[/url] — чем отличается комплексный пакет от минимального?

  2. Чем [url=https://prodvizhenie-sajta-s-oplatoj-za-rezultat.ru]продвижение сайта с оплатой за результат[/url] рискованно для исполнителя?

  3. [url=https://top-seo-prodvizhenie.ru]Топ seo продвижение[/url] — как правильно сформулировать KPI с подрядчиком?

  4. Как выбрать пакет, когда решаешь [url=https://zakazat-prodvizhenie-sajta.ru]заказать продвижение сайта[/url]: базовый или комплексный?

  5. I have been playing on this site for a few months now and the experience is really smooth. The withdrawal speed is impressive and customer support always answers quickly. If you are looking for a reliable place to enjoy your favorite games this is definitely worth trying. thm4king

  6. Signing in never feels complicated here and the live dealer tables are absolutely top notch. I love how the welcome bonus rolls out without any confusing requirements. Every spin feels fair and the withdrawal process is incredibly transparent. This is exactly what I wanted from a modern gaming hub. 56xbetlogin

  7. Anyone looking for a trustworthy spot with great vibes should definitely take a look. I have been playing here for a few weeks now and the interface feels so welcoming for locals. Withdrawals are fast and the game selection matches exactly what we need down here. Save this page and tell your friends about mexplaymxcasino

  8. [7097]ba999 Official Login | বিকাশ পেমেন্ট ও সেরা ক্যাসিনো বোনাস,ba999 অ্যাপ ডাউনলোড করে উপভোগ করুন সেরা স্লট গেমের নিয়ম ও আকর্ষণীয় অনলাইন ক্যাসিনো বোনাস। বিকাশ দিয়ে সহজে লেনদেন করতে আজই জয়েন করুন। visit: ba999

  9. [9524]77cuci Official Login | Trusted Online Slots & Live Casino Malaysia,77cuci provides a seamless experience for online slots in Malaysia. Download the official app for fast payouts and secure access to live games. Join now! visit: 77cuci

댓글 달기

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