Skip to content

Instantly share code, notes, and snippets.

@stephen-maina
Created May 5, 2015 19:15
Show Gist options
  • Save stephen-maina/fb8e1f5b675a2f20b1b3 to your computer and use it in GitHub Desktop.
Save stephen-maina/fb8e1f5b675a2f20b1b3 to your computer and use it in GitHub Desktop.
O(log(N + M))
class Solution {
public int solution(int N, int M) {
// write your code in Java SE 8
return N/gcd(N,M);
}
public int gcd(int N,int M){
if(N%M==0){
return M;
}else{
return gcd(M,N%M);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment