-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava.java
More file actions
29 lines (26 loc) · 717 Bytes
/
Copy pathJava.java
File metadata and controls
29 lines (26 loc) · 717 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
28
29
import java.util.*;
class Solution {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] temp = new int[n];
for (int i = 0; i < n; i++) {
int t = in.nextInt();
temp[i] = t;
}
in.close();
int abs = 5526;
int value = 5526;
for(int i = 0; i < n; i++) {
int _abs = Math.abs(temp[i]);
if(_abs < abs){
abs = _abs;
value = temp[i];
}
else if(_abs == abs && temp[i] > 0){
value = temp[i];
}
}
System.out.println(n == 0 ? 0 : value);
}
}