기록하는 개발자

[프로그래머스][코딩테스트 고득점 Kit][java] 큰 수 만들기 본문

Algorithm

[프로그래머스][코딩테스트 고득점 Kit][java] 큰 수 만들기

밍맹030 2023. 8. 21. 17:44
728x90

https://school.programmers.co.kr/learn/courses/30/lessons/42883

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

전체 코드

class Solution {
    public String solution(String number, int k) {
        StringBuilder sb = new StringBuilder();
        int index = 0, now = 0;
        
         for(int i=0; i<number.length()-k; i++){
            now = 0;
            for(int j=index; j<=i+k; j++){ 
                if(now < number.charAt(j)-'0'){
                    now = number.charAt(j)-'0';
                    index = j+1;
                }    
                // System.out.println("now : "+now+"   i : "+ i + "   j : "+ j+ "   index : "+ index);
            }
            sb.append(now);
            // System.out.println("[ sb : "+sb+" ]");

        }
        return sb.toString();
    }
}

testcase의 now, i, j , index, sb 출력 결과

728x90