Notice
Recent Posts
Recent Comments
Link
«   2026/06   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Tags
more
Archives
Today
Total
관리 메뉴

개발자도전

[LeetCode] Check If N and Its Double Exist 본문

LeetCode

[LeetCode] Check If N and Its Double Exist

도do 2023. 1. 28. 00:37
728x90

[문제]

Given an array arr of integers, check if there exist two indices i and j such that :

  • i != j
  • 0 <= i, j < arr.length
  • arr[i] == 2 * arr[j]

주어진 정수 배열이 주어졌을 때, 두 정수를 a, b라고 할 때 a = 2b 인 값을 구해라.

 

[입출력 예]

Input: arr = [10,2,5,3]
Output: true
Explanation: For i = 0 and j = 2, arr[i] == 10 == 2 * 5 == 2 * arr[j]
Input: arr = [3,1,7,11]
Output: false
Explanation: There is no i and j that satisfy the conditions.

 

[답]

이중 for문을 사용해서 값을 비교해주었다.

arr[i]의 값이 arr[j]의 값의 2배인지와 그 반대의 경우의 조건을 추가해서 return 값을 주었다.

728x90

'LeetCode' 카테고리의 다른 글

[LeetCode] 35. Search Insert Position - java  (0) 2023.02.01
[LeetCode] Valid Mountain Array  (0) 2023.01.31
[LeetCode] Remove Duplicates from Sorted Array  (0) 2023.01.26
[LeetCode] Remove Element  (0) 2023.01.26
[LeetCode] Merge Sorted Array  (0) 2023.01.25
Comments