aboutsummaryrefslogtreecommitdiff
path: root/other/mirror_reflection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'other/mirror_reflection.cpp')
-rw-r--r--other/mirror_reflection.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/other/mirror_reflection.cpp b/other/mirror_reflection.cpp
new file mode 100644
index 0000000..447ce5e
--- /dev/null
+++ b/other/mirror_reflection.cpp
@@ -0,0 +1,21 @@
+#include "leetcode.h"
+
+class Solution {
+public:
+ int mirrorReflection(int p, int q) {
+ while ((p % 2 == 0) && (q % 2 == 0)) {
+ p /= 2;
+ q /= 2;
+ }
+ if ((p % 2) == 0 && (q % 2) != 0)
+ return 2;
+ if ((p % 2) != 0 && (q % 2) != 0)
+ return 1;
+ return 0;
+ }
+};
+
+int main() {
+ Solution obj;
+ cout << obj.mirrorReflection(2, 1);
+}