|
|
return gcd(b,b%a)
to return gcd(b,a%b)
it works. In the examples I am trying both the algorithms work, but when I use this gcd method on online coding problem, return gcd(b,a%b)
works but not the other. Can someone throw some light and provide an example where return gcd(b,b%a)
fails?a
is 0, b%a
would fail. Whereas in a%b
, b
cannot be 0 because of the return statement in if(b==0)
.
|
|
|
|