• 문제 링크
Largest Number At Least Twice of Others - LeetCode
Can you solve this real interview question? Largest Number At Least Twice of Others - You are given an integer array nums where the largest integer is unique. Determine whether the largest element in the array is at least twice as much as every other numbe
leetcode.com
• 풀이 코드
public class Solution {
public int dominantIndex(int[] nums) {
int idx = 0;
for (int i = 0; i < nums.length; i++) if (nums[idx] < nums[i]) idx = i;
for (int i = 0; i < nums.length; i++) if (idx != i && nums[idx] < nums[i] * 2) return -1;
return idx;
}
}'Problem Solving > LeetCode' 카테고리의 다른 글
| [LeetCode] 762. Prime Number of Set Bits in Binary Representation - Java (0) | 2026.10.11 |
|---|---|
| [LeetCode] 748. Shortest Completing Word - Java (0) | 2026.10.10 |
| [LeetCode] 746. Min Cost Climbing Stairs - Java (0) | 2026.10.08 |
| [LeetCode] 744. Find Smallest Letter Greater Than Target - Java (0) | 2026.10.07 |
| [LeetCode] 733. Flood Fill - Java (0) | 2026.10.06 |
댓글