Easy C++ Solution simple


#1

int Solution::gcd(int A, int B) {
int x,y;
if(A>B) x=B;
if(B>A) x=A;
if(A==0&&B!=0) return B;
if(A!=0 && B==0) return A;
if(A==0&&B==0) return 0;
while(x!=0){
if(A%x==0&&B%x==0){
y=x;
break;
}
x–;
}
return y;
}


#2

We will get the same result without using extra var y.