Posts Trailing Zeroes (InterviewBit)
Post
Cancel

Trailing Zeroes (InterviewBit)

PROBLEM DESCRIPTION

Given an integer A, count and return the number of trailing zeroes.

SOLUTION

APPROACH 1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public class Solution {

    public int solve(int A) {

        int c = 0;

        for(int i=0; i<32; i++){

            if( (A&1) == 0 ){
                c++;
                A = (A>>1);
            }else
                break;

        }

        return c;

    }

}
This post is licensed under CC BY 4.0 by the author.