We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
leetcode/leetcoding_challenge/2024/aug2024/week4/number_complement.cpp
1 parent e98bda5 commit 091175eCopy full SHA for 091175e
src/onlinePlatform/leetcode/leetcoding_challenge/2024/aug2024/week4/number_complement.cpp
@@ -0,0 +1,29 @@
1
+#include <algorithm>
2
+#include <vector>
3
+#include <queue>
4
+#include <set>
5
+#include <limits>
6
+#include <map>
7
+#include <unordered_set>
8
+#include <unordered_map>
9
+#include <iterator>
10
+#include <sstream>
11
+#include <iostream> // includes cin to read from stdin and cout to write to stdout
12
+using namespace std; // since cin and cout are both in namespace std, this saves some text
13
+
14
+class Solution {
15
+public:
16
+ int findComplement(int num) {
17
+ int answer = 0;
18
+ int base = 1;
19
+ while (num > 1) {
20
+ if (num % 2 == 0) {
21
+ answer += base ;
22
+ }
23
+ num /= 2;
24
+ base *= 2;
25
26
27
+ return answer;
28
29
+};
0 commit comments