1998. GCD Sort of an Array
https://leetcode.com/problems/gcd-sort-of-an-array
Description
You are given an integer array nums
, and you can perform the following operation any number of times on nums
:
Swap the positions of two elements
nums[i]
andnums[j]
ifgcd(nums[i], nums[j]) > 1
wheregcd(nums[i], nums[j])
is the greatest common divisor ofnums[i]
andnums[j]
.
Return true
if it is possible to sort nums
in non-decreasing order using the above swap method, or false
otherwise.
Example 1:
Example 2:
Example 3:
Constraints:
1 <= nums.length <= 3 * 104
2 <= nums[i] <= 105
ac
Previous1997. First Day Where You Have Been in All the RoomsNext1999. Smallest Greater Multiple Made of Two Digits
Last updated