/*
* @lc app=leetcode.cn id=1250 lang=typescript
*
* [1250] 检查「好数组」
*/
// @lc code=start
function isGoodArray(nums: number[]): boolean {}
// @lc code=end
function isGoodArray(nums: number[]): boolean {
function gcd(a: number, b: number): number {
return b ? gcd(b, a % b) : a
}
let res = 0
for (const a of nums) {
res = gcd(res, a)
}
return res === 1
}
test.each([
{ input: { nums: [12, 5, 7, 23] }, output: true },
{ input: { nums: [29, 6, 10] }, output: true },
{ input: { nums: [3, 6] }, output: false },
])('input: nums = $input.nums', ({ input: { nums }, output }) => {
expect(isGoodArray(nums)).toEqual(output)
})