Skip to content

Instantly share code, notes, and snippets.

@oxlb
Created July 30, 2020 11:17
Show Gist options
  • Save oxlb/8df1f356ba6eab713ab6b43cdc6cec66 to your computer and use it in GitHub Desktop.
Save oxlb/8df1f356ba6eab713ab6b43cdc6cec66 to your computer and use it in GitHub Desktop.
Codility Devide Zero
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