File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class Main {
6+
7+ public static void main (String [] args ) throws IOException {
8+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
9+ StringTokenizer st;
10+
11+ int n = Integer . parseInt(br. readLine());
12+
13+ int [] arr = new int [n];
14+
15+ st = new StringTokenizer (br. readLine());
16+
17+ for (int i = 0 ; i < n; i++ ) {
18+ arr[i] = Integer . parseInt(st. nextToken());
19+ }
20+
21+ int left = 0 ;
22+ int right = n - 1 ;
23+ int temp = 987654321 ;
24+ int res = 0 ;
25+
26+ while (left < right) {
27+ int sum = arr[left] + arr[right];
28+ if (sum < 0 ) {
29+ left++ ;
30+ } else if (sum > 0 ) {
31+ right-- ;
32+ } else {
33+ res = 0 ;
34+ break ;
35+ }
36+ if (temp> Math . abs(sum)){
37+ res = sum;
38+ temp = Math . abs(sum);
39+ }
40+ }
41+
42+ System . out. println(res);
43+ }
44+ }
45+ ```
You can’t perform that action at this time.
0 commit comments