3875. Construct Uniform Parity Array I
class Solution {
public boolean uniformArray(int[] nums1) {
int oddCount = 0, evenCount = 0;
for (int x : nums1) {
if (x % 2 == 0) evenCount++;
else oddCount++;
}
boolean allEven = (oddCount == 0 || oddCount >= 2);
boolean allOdd = (evenCount == 0 || oddCount >= 1);
return allEven || allOdd;
}
}
class Solution:
def uniformArray(self, nums1):
oddCount = 0
evenCount = 0
for x in nums1:
if x % 2 == 0:
evenCount += 1
else:
oddCount += 1
allEven = (oddCount == 0 or oddCount >= 2)
allOdd = (evenCount == 0 or oddCount >= 1)
return allEven or allOdd
class Solution {
public:
bool uniformArray(vector<int>& nums1) {
int oddCount = 0;
int evenCount = 0;
for (int x : nums1) {
if (x % 2 == 0)
evenCount++;
else
oddCount++;
}
bool allEven = (oddCount == 0 || oddCount >= 2);
bool allOdd = (evenCount == 0 || oddCount >= 1);
return allEven || allOdd;
}
};
class Solution {
uniformArray(nums1) {
let oddCount = 0;
let evenCount = 0;
for (const x of nums1) {
if (x % 2 === 0)
evenCount++;
else
oddCount++;
}
const allEven = (oddCount === 0 || oddCount >= 2);
const allOdd = (evenCount === 0 || oddCount >= 1);
return allEven || allOdd;
}
}