LeetCode > 1346. Check If N and Its Double Exist

2025. 4. 3. 22:57·🔒Algorithm

문제

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

풀이

쉽게 풀 수 있다. 시간 복잡도는 O(n^2) 이다.

/**
 * @param {number[]} arr
 * @return {boolean}
 */
var checkIfExist = function(arr) {
    for(let i =0; i<=arr.length; ++i){
        for(let j=i+1; j<arr.length; ++j){
            if(arr[i]*2===arr[j]||arr[i]===2*arr[j]){
                return true
            }
        }   
    }
    return false
};

 

'🔒Algorithm' 카테고리의 다른 글

LeetCode [JS] > 2780. Minimum Index of a Valid Split  (0) 2025.04.05
LeetCode > 2208 Minimum Operations to Halve Array Sum  (0) 2025.04.05
LeetCode > 806. Number of Lines To Write String  (0) 2025.04.02
LeetCode > 2022. Convert 1D Array Into 2D Array  (0) 2025.03.29
LeetCode > 2591. Distribute Money to Maximum Children  (0) 2025.03.28
'🔒Algorithm' 카테고리의 다른 글
  • LeetCode [JS] > 2780. Minimum Index of a Valid Split
  • LeetCode > 2208 Minimum Operations to Halve Array Sum
  • LeetCode > 806. Number of Lines To Write String
  • LeetCode > 2022. Convert 1D Array Into 2D Array
devWarrior
devWarrior
  • devWarrior
    devWarrior
    devWarrior
  • 전체
    오늘
    어제
    • 🧩Dev (263)
      • ⭐FE (34)
      • 🔒Algorithm (155)
      • ➕Etc. (11)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
    • 글쓰기
    • 관리
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    티스토리챌린지
    nodejs
    js
    코테
    실버1
    react
    알고리즘
    프론트엔드
    BFS
    dp
    구현
    javascript
    DFS
    그리디
    leetcode
    백준
    FE
    실버4
    Algorithm
    코딩테스트
    Easy
    node.js
    실버3
    오블완
    자바스크립트
    자스
    골드5
    실버2
    프로그래머스
    Lv2
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
devWarrior
LeetCode > 1346. Check If N and Its Double Exist
상단으로

티스토리툴바