-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtil.java
More file actions
53 lines (42 loc) · 1.24 KB
/
Copy pathUtil.java
File metadata and controls
53 lines (42 loc) · 1.24 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
52
53
private int solution(int[]A, int[]B)
{
int n = A.length;
int[] diff = new int[1000];
int notEmpty =0;
for (int i = 0; i < n; i++){
if ((Arrays.binarySearch(A, B[i]))<0){
diff[i] = A[i];
notEmpty ++;
}
}
if(notEmpty==0)
return 0;
int min = Integer.MAX_VALUE;
for (Integer x: diff)
if(x.intValue() != 0)
min = Math.min(min, x);
//Math.floorMod(x, y);
//Math.pow(a, b)(a, b)(a, b)
return Arrays.binarySearch(diff, min)+1;
}
private static boolean isIntegerValue (Double d)
{
try {
String someString = d.toString();
if (someString.matches("\\d+")){//optional minus and at least one digit
return true;
} else {
return false;
}
} catch (Exception e) {
System.out.println("Exception:"+e.getMessage());
return false;
}
}
private static int getSqrtRoot (int x){
Double sqrt = Math.sqrt(x);
if (!isIntegerValue(sqrt))
return 1;
else
return sqrt.intValue();
}