Java Sol simple with diff cases


#1

public class Solution {
public int gcd(int A, int B) {

    int hcf= 0;
    
    //Case 1
    if(A==1 || B==1){
      hcf = 1;
    }
    
    //Case 2
    if(A==0 || B==0){
        if(A==0){
            hcf = B;
        } 
        else hcf = A;
        
    }
    
    //generic case
    for(int i=1;i<=A && i<=B; i++){
        
        if(A%i == 0 && B%i==0){
            hcf = i;
        }
        
    }
    
    return hcf;
}

}