-
Notifications
You must be signed in to change notification settings - Fork 1
/
22_avoidObstacles
50 lines (45 loc) · 1.25 KB
/
22_avoidObstacles
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
int solution(int[] inputArray) {
Arrays.sort(inputArray);
int res;
for(int i=1;;i++){
res=0;
for(int a : inputArray){
if(a%i==0) break;
else res++;
if(res == inputArray.length) return i;
}
}
}
/*// Online Java Compiler
// Use this editor to write, compile and run your Java code online
import java.util.*;
class HelloWorld {
public static void main(String[] args) {
int[] arr= {5,3,6,7,9};
int sol;
boolean flag=false;
System.out.println(arr.length);
Arrays.sort(arr);
for(int i=1;;i++){
sol=0;
for(int x : arr){
System.out.println("x = "+x);
System.out.println("***** i = "+i);
if(x%i==0) {
System.out.println(x+" % "+i+" == 0");
System.out.println("-----------------");
break;
}
else{
sol++;
System.out.println("sol = "+sol);
}
if(sol == arr.length){
flag = true;
System.out.println("i = "+i);
}
}
if(flag) break;
}
}
}*/