-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogrammers70129.java
More file actions
35 lines (32 loc) · 1014 Bytes
/
programmers70129.java
File metadata and controls
35 lines (32 loc) · 1014 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.*;
class Solution {
public int[] solution(String s) {
int[] answer = {};
String loopResult = s;
int loopCount = 0;
int zeros = 0;
while (!loopResult.equals("1")){
StringTokenizer st = new StringTokenizer(loopResult, "0", true);
loopResult = "";
while (st.hasMoreTokens()){
String token = st.nextToken();
if (token.charAt(0) == '1') {
loopResult = loopResult + token;
}
else { //token.charAt(0) == '0'
zeros+=token.length();
}
}//while
int length = loopResult.length();
String buff = "";
do {
buff = length%2 + buff;
length /= 2;
} while(length != 0);
loopResult = buff;
loopCount++;
}//while
answer = new int[] {loopCount, zeros};
return answer;
}
}