Check If It Is a Good Array LeetCode solution in Java

1
class Solution {
2
public boolean isGoodArray(int[] nums) {
3
int gcd = nums[0];
4
for (int i = 1; i < nums.length; i++) {
5
gcd = GCD(gcd, nums[i]);
6
if (gcd == 1) return true;
7
}
8
return gcd == 1;
9
}
10

11
int GCD(int a, int b) {
12
if (b == 0) {
13
return a;
14
} else {
15
return GCD(b, a % b);
16
}
17
}
18
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0