Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by lidiakulikova on 21/02/2018.
- */
- public class Binarian {
- public static int getBinarian(int[] A){
- int total = 0;
- for (int x : A){
- total += (int)Math.pow(2, x);
- }
- return total;
- }
- public static int solution(int[] A) {
- // write your code in Java SE 8
- int k = getBinarian(A);
- int remainder = k;
- int count =0;
- while (remainder >= 2){
- double c = Math.log(remainder) / Math.log(2);
- remainder = remainder - (int)Math.pow(2, (int) c);
- count += 1;
- }
- if (remainder == 1){
- count +=1; //2^0
- }
- return count;
- }
- public static void main(String[] args){
- System.out.println(solution(new int[]{2, 2}));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement