- Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSolution747.java
More file actions
Latest commit
executable file
·27 lines (26 loc) · 765 Bytes
/
Copy pathSolution747.java
File metadata and controls
executable file
·27 lines (26 loc) · 765 Bytes
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
/**
* Created by slade on 2019/7/12.
*/
publicclassSolution747 {
publicintdominantIndex(int[] nums) {
intidx = -1;
if (nums.length == 1) return0;
intmaxValue = -1;
intsecondValue = -1;
for (inti = 0; i < nums.length; i++) {
if (nums[i] >= maxValue) {
secondValue = maxValue;
maxValue = nums[i];
idx = i;
} elseif (nums[i] > secondValue) {
secondValue = nums[i];
}
}
returnmaxValue >= secondValue * 2 ? idx : -1;
}
publicstaticvoidmain(String[] args) {
Solution747s = newSolution747();
int[] n = {0,0,0,1};
System.out.println(s.dominantIndex(n));
}
}