GCD using Euclid
Java
Medium
5 views
Problem Description
Task: return gcd(a,b) using while loop (Euclid algorithm).
Output Format
Return value
Constraints
Work with negatives too.
Official Solution
static int gcd(int a,int b){a=a<0?-a:a;b=b<0?-b:b;while(b!=0){int t=a%b;a=b;b=t;}return a;}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!