Skip to content

Commit ee28f9f

Browse files
authored
Update Solution.java
1 parent 3614307 commit ee28f9f

File tree

1 file changed

+3
-6
lines changed
  • src/main/java/g3101_3200/s3115_maximum_prime_difference

1 file changed

+3
-6
lines changed

src/main/java/g3101_3200/s3115_maximum_prime_difference/Solution.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,24 @@
55
public class Solution {
66
public int maximumPrimeDifference(int[] nums) {
77
int n = nums.length;
8-
98
int i = 0;
10-
119
while (i < n && !check(nums[i])) {
1210
i++;
1311
}
1412
int j = n - 1;
1513
while (j >= 0 && !check(nums[j])) {
1614
j--;
1715
}
18-
1916
return j - i;
2017
}
2118

2219
private boolean check(int n) {
23-
if (n < 2) return false;
24-
20+
if (n < 2) {
21+
return false;
22+
}
2523
for (int i = 2; i <= Math.sqrt(n); i++) {
2624
if (n % i == 0) return false;
2725
}
28-
2926
return true;
3027
}
3128
}

0 commit comments

Comments
 (0)