-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRough.java
More file actions
51 lines (34 loc) · 1.02 KB
/
Copy pathRough.java
File metadata and controls
51 lines (34 loc) · 1.02 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.util.*;
class Rough{
public static int secLarge(int[] arr){
int max = Integer.MIN_VALUE;
for(int i = 0; i < arr.length;i++){
if(arr[i] > max){
max = arr[i];
}
}
int sec_max = Integer.MIN_VALUE;
for(int i = 0; i < arr.length; i++){
if(arr[i] > sec_max && arr[i] != max){
sec_max = arr[i];
}
}
return sec_max;
}
public static int[] twoSumHashMap(int[] arr,int target){
HashMap<Integer,Integer> map = new HashMap<>();
for(int i = 0;i < arr.length;i++){
int complement = target - arr[i];
if(map.containsKey(complement)){
return new int[]{map.get(complement),i};
}
map.put(arr[i],i);
}
return new int[]{-1,-1};
}
public static void main(String[] args) {
int[] arr = {5,5,5,5,5,5};
int sec_max = secLarge(arr);
System.out.println(sec_max);
}
}