File tree Expand file tree Collapse file tree 2 files changed +19
-13
lines changed
프로그래머스/2/70129. 이진 변환 반복하기 Expand file tree Collapse file tree 2 files changed +19
-13
lines changed Original file line number Diff line number Diff line change 44
55### 성능 요약
66
7- 메모리: 93.8 MB, 시간: 22.85 ms
7+ 메모리: 83.7 MB, 시간: 18.35 ms
88
99### 구분
1010
1616
1717### 제출 일자
1818
19- 2025년 05월 29일 17:02:28
19+ 2025년 05월 29일 17:14:17
2020
2121### 문제 설명
2222
Original file line number Diff line number Diff line change 11class Solution {
22 public int [] solution (String s ) {
33 int [] answer = new int [2 ];
4- int remove_cnt = 0 ;
5- int loop_cnt = 0 ;
4+ int removeCnt = 0 ;
5+ int loopCnt = 0 ;
66
77 //이진 변환 루프
88 while (!s .equals ("1" )){
9- int before = s .length ();
9+ int lenBefore = s .length ();
1010 s =s .replace ("0" ,"" );
11- int after = s .length ();
11+ int lenAfter = s .length ();
1212
1313 //제거된 0의 갯수 갱신
14- remove_cnt += (before - after );
14+ removeCnt += (lenBefore - lenAfter );
1515
1616 int cnt =0 ;
17+
18+
19+ //이진 변환 코드는 Java에서 API를 제공함
20+ // s=Integer.toBinaryString(after);
21+
1722 String temp = "" ;
18- while (after >1 ){
23+ while (lenAfter >1 ){
1924
20- temp = (after %2 ) + temp ;
21- after /=2 ;
25+ temp = (lenAfter %2 ) + temp ;
26+ lenAfter /=2 ;
2227
2328 cnt ++;
2429 }
2530
2631 s = "1" +temp ;
27- loop_cnt ++;
32+
33+ loopCnt ++;
2834 }
2935
30- answer [0 ] = loop_cnt ;
31- answer [1 ] = remove_cnt ;
36+ answer [0 ] = loopCnt ;
37+ answer [1 ] = removeCnt ;
3238 return answer ;
3339 }
3440}
You can’t perform that action at this time.
0 commit comments