Skip to content

Commit 46c1d3e

Browse files
🔢 Day 17
1 parent cd2cee7 commit 46c1d3e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
## Week 3 🚧
2626
1. [Range Sum of BST](https://leetcode.com/explore/challenge/card/november-leetcoding-challenge/566/week-3-november-15th-november-21st/3532/) ➡️ [CPP Solution](Week3/rangeSumBST.cpp)
2727
2. [Longest Mountain in Array](https://leetcode.com/explore/challenge/card/november-leetcoding-challenge/566/week-3-november-15th-november-21st/3533/) ➡️ [CPP Solution](Week3/longestMountain.cpp)
28+
3. [Mirror Reflection](https://leetcode.com/explore/challenge/card/november-leetcoding-challenge/566/week-3-november-15th-november-21st/3534/) ➡️ [CPP Solution](Week3/mirrorReflection.cpp)
2829

2930
## Week 4 🚧
3031
Coming soon...

Week3/mirrorReflection.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Ref: https://www.youtube.com/watch?v=_xIBOUWEq1c
2+
3+
class Solution {
4+
public:
5+
int mirrorReflection(int p, int q) {
6+
int reflection = p, extension = q;
7+
8+
while(reflection % 2 == 0 && extension % 2 == 0) {
9+
reflection /= 2;
10+
extension /= 2;
11+
}
12+
13+
if(extension % 2 == 0 && reflection % 2 == 1) return 0;
14+
if(extension % 2 == 1 && reflection % 2 == 0) return 2;
15+
if(extension % 2 == 1 && reflection % 2 == 1) return 1;
16+
17+
return -1;
18+
}
19+
};

0 commit comments

Comments
 (0)