mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-09 15:59:06 +01:00
problems: add mirror reflection
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
08a623bb50
commit
826b402dd1
1 changed files with 18 additions and 0 deletions
18
problems/mirror-reflection.cpp
Normal file
18
problems/mirror-reflection.cpp
Normal file
|
@ -0,0 +1,18 @@
|
|||
class Solution {
|
||||
public:
|
||||
int mirrorReflection(int p, int q)
|
||||
{
|
||||
auto lcm = p * q / std::gcd(p, q);
|
||||
auto x = lcm / p;
|
||||
auto y = lcm / q;
|
||||
|
||||
if (x % 2 == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (y % 2 == 0) {
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
};
|
Loading…
Reference in a new issue