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