-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathfind_min_max.java
More file actions
50 lines (33 loc) · 1 KB
/
find_min_max.java
File metadata and controls
50 lines (33 loc) · 1 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
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class GFG {
public static Integer findMin(List<Integer> list)
{
if (list == null || list.size() == 0) {
return Integer.MAX_VALUE;
}
List<Integer> sortedlist = new ArrayList<>(list);
Collections.sort(sortedlist);
return sortedlist.get(0);
}
public static Integer findMax(List<Integer> list)
{
if (list == null || list.size() == 0) {
return Integer.MIN_VALUE;
}
List<Integer> sortedlist = new ArrayList<>(list);
Collections.sort(sortedlist);
return sortedlist.get(sortedlist.size() - 1);
}
public static void main(String[] args)
{
List<Integer> list = new ArrayList<>();
list.add(44);
list.add(11);
list.add(22);
list.add(33);
System.out.println("Min: " + findMin(list));
System.out.println("Max: " + findMax(list));
}
}