본문 바로가기

Algorithm/Implementation

(C++) - LeetCode (easy) 1346. Check If N and Its Double Exist

반응형

https://leetcode.com/problems/check-if-n-and-its-double-exist/description/

 

LeetCode - The World's Leading Online Programming Learning Platform

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

간단 구현문제였습니다.

📕 풀이방법

📔 풀이과정

조건대로 arr에 대해 2차원 for loop를 수행하면서 i!=j면서 arr[i] == 2 * arr[j]인 경우를 찾습니다.

📔 정답 출력 | 반환

 

 

조건에 만족하면 true, 아니라면 false를 반환합니다.


📕 Code

📔 C++

class Solution {
public:
    bool checkIfExist(vector<int>& arr) {
        for(int i = 0; i < arr.size(); i++) {
            for(int j = 0; j < arr.size(); j++) {
                if(i == j) continue;
                if(arr[i] == 2 * arr[j]) return true;
            }
        }
        return false;
    }
};

*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.