InterviewBit - Greatest Common Divisor  

by ne on 2021-03-02 under Algo tagged with interviewbit

This problem is a property of InterviewBit (www.interviewbit.com). Full details of the question, and if you want to try it out yourself, proceed to interviewbit : https://www.interviewbit.com/problems/greatest-common-divisor/
Here's the implementation


public class Solution {
    public int gcd(int A, int B) {
        int min=Math.min(A,B);
        int gcd=Math.max(A,B);
        while(min>0){
            if(A%min==0 && B%min==0){
                gcd=min;
                break;
            }
            min--;
        }
        return gcd;
    }
}