From 89357b21ceda39f852f209c808130583aec695df Mon Sep 17 00:00:00 2001 From: Rajaram Date: Sat, 17 Dec 2022 16:39:18 +0530 Subject: [PATCH] Time: 7 ms, Memory: 10 MB - LeetHub --- .../check-if-n-and-its-double-exist.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 check-if-n-and-its-double-exist/check-if-n-and-its-double-exist.cpp diff --git a/check-if-n-and-its-double-exist/check-if-n-and-its-double-exist.cpp b/check-if-n-and-its-double-exist/check-if-n-and-its-double-exist.cpp new file mode 100644 index 0000000..a023341 --- /dev/null +++ b/check-if-n-and-its-double-exist/check-if-n-and-its-double-exist.cpp @@ -0,0 +1,17 @@ +class Solution { +public: + int getExistIndex(vector& arr, int element){ + for(int i = 0; i < arr.size(); i++){ + if(arr[i] == element) return i; + } + return -1; + } + bool checkIfExist(vector& arr) { + for(int i = 0; i < arr.size(); i++){ + int j = getExistIndex(arr, arr[i]*2); + if(i!=j && j >= 0) return true; + } + return false; + + } +}; \ No newline at end of file