Created
May 5, 2015 19:15
-
-
Save stephen-maina/fb8e1f5b675a2f20b1b3 to your computer and use it in GitHub Desktop.
O(log(N + M))
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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