0%

[題解]Leetcode 858 Mirror Reflection

858 Mirror Reflection

題目連結

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution {
public:
int gcd(int a,int b){
if(a == 0)return b;
return gcd(b % a,a);
}

int mirrorReflection(int p, int q) {
int len = p * q / gcd(q,p);
int a = (len / p) % 2,b = (len / q) % 2;
if(a == 0 && b == 1)return 0;
else if(a == 1 && b == 1)return 1;
else return 2;

}
};