문제
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 |