Created
July 30, 2020 11:17
-
-
Save oxlb/8df1f356ba6eab713ab6b43cdc6cec66 to your computer and use it in GitHub Desktop.
Codility Devide Zero
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int solution(String s) { | |
char[] val = s.toCharArray(); | |
int sum = 0; | |
while(val[sum]=='0') { | |
sum++; | |
} | |
int reduce = 0; | |
for(int k=val.length-1; k>=sum; k--){ | |
if(val[k] =='1'){ | |
reduce+=2; | |
}else{ | |
reduce++; | |
} | |
} | |
return reduce-1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment