- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem414.java
More file actions
Latest commit
25 lines (24 loc) · 624 Bytes
/
Copy pathProblem414.java
File metadata and controls
25 lines (24 loc) · 624 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
classProblem414 {
publicstaticvoidmain(String[] args) {
int[] nums = newint[]{3,2,1};
System.out.println(newProblem414().thirdMax(nums));
}
publicintthirdMax(int[] nums) {
intc = 0;
intk = 0;
while (k < 2) {
if (c >= nums.length) break;
for (inti = c; i < nums.length; i++) {
if(nums[i] > nums[c]) {
inttmp = nums[c];
nums[c] = nums[i];
nums[i] = tmp;
}
}
if (c > 0 && nums[c] != nums[c-1]) k++;
c++;
}
if (k < 2) returnnums[0];
returnnums[c-1];
}
}