File tree 2 files changed +21
-0
lines changed
2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 161
161
733|[ Flood Fill] ( ./0733-flood-fill.js ) |Easy|
162
162
739|[ Daily Temperatures] ( ./0739-daily-temperatures.js ) |Medium|
163
163
746|[ Min Cost Climbing Stairs] ( ./0746-min-cost-climbing-stairs.js ) |Easy|
164
+ 747|[ Largest Number At Least Twice of Others] ( ./0747-largest-number-at-least-twice-of-others.js ) |Easy|
164
165
762|[ Prime Number of Set Bits in Binary Representation] ( ./0762-prime-number-of-set-bits-in-binary-representation.js ) |Easy|
165
166
784|[ Letter Case Permutation] ( ./0784-letter-case-permutation.js ) |Medium|
166
167
791|[ Custom Sort String] ( ./0791-custom-sort-string.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 747. Largest Number At Least Twice of Others
3
+ * https://leetcode.com/problems/largest-number-at-least-twice-of-others/
4
+ * Difficulty: Easy
5
+ *
6
+ * You are given an integer array nums where the largest integer is unique.
7
+ *
8
+ * Determine whether the largest element in the array is at least twice as much
9
+ * as every other number in the array. If it is, return the index of the largest
10
+ * element, or return -1 otherwise.
11
+ */
12
+
13
+ /**
14
+ * @param {number[] } nums
15
+ * @return {number }
16
+ */
17
+ var dominantIndex = function ( nums ) {
18
+ const max = Math . max ( ...nums ) ;
19
+ return nums . find ( n => n !== max && n > max / 2 ) ? - 1 : nums . indexOf ( max ) ;
20
+ } ;
You can’t perform that action at this time.
0 commit comments