747. Largest Number At Least Twice of Others Easy

@problem@discussion
#Array#Sorting



1/**
2 * [747] Largest Number At Least Twice of Others
3 *
4 * You are given an integer array nums where the largest integer is unique.
5 * Determine whether the largest element in the array is at least twice as much as every other number in the array. If it is, return the index of the largest element, or return -1 otherwise.
6 *  
7 * Example 1:
8 * 
9 * Input: nums = [3,6,1,0]
10 * Output: 1
11 * Explanation: 6 is the largest integer.
12 * For every other number in the array x, 6 is at least twice as big as x.
13 * The index of value 6 is 1, so we return 1.
14 * 
15 * Example 2:
16 * 
17 * Input: nums = [1,2,3,4]
18 * Output: -1
19 * Explanation: 4 is less than twice the value of 3, so we return -1.
20 * 
21 *  
22 * Constraints:
23 * 
24 * 	2 <= nums.length <= 50
25 * 	0 <= nums[i] <= 100
26 * 	The largest element in nums is unique.
27 * 
28 */
29pub struct Solution {}
30
31// problem: https://leetcode.com/problems/largest-number-at-least-twice-of-others/
32// discuss: https://leetcode.com/problems/largest-number-at-least-twice-of-others/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36impl Solution {
37    pub fn dominant_index(nums: Vec<i32>) -> i32 {
38        0
39    }
40}
41
42// submission codes end
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[test]
49    fn test_747() {
50    }
51}
52


Back
© 2025 bowen.ge All Rights Reserved.