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.
2 parents 173402a + 428b305 commit 4c1730eCopy full SHA for 4c1730e
1346. Check If N and Its Double Exist
@@ -0,0 +1,18 @@
1
+class Solution {
2
+public:
3
+ bool checkIfExist(vector<int>& arr) {
4
+ int n = arr.size();
5
+ bool cnt[2001] = {false}; // Boolean array to track whether a number has been seen
6
+
7
+ for(int i = 0 ; i < n ; i++) {
8
+ int x = arr[i] * 2 + 1000;
9
+ if(x >= 0 && x <= 2000 && cnt[x]) //Check if 2 * arr[i] exists and not exceed the range
10
+ return true;
11
+ x = arr[i] / 2 + 1000;
12
+ if(arr[i] % 2 == 0 && cnt[x]) //ensure arr[i] is even and check if arr[i] / 2 exists
13
14
+ cnt[arr[i] + 1000] = 1;
15
+ }
16
+ return false;
17
18
+};
0 commit comments