3875. Construct Uniform Parity Array I
/**
* Problem: LeetCode 3875 - Construct Uniform Parity Array I
* Difficulty: Easy
* Language: Java
* Author: CodeByTushu
*/
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;
}
}
"""
Problem: LeetCode 3875 - Construct Uniform Parity Array I
Difficulty: Easy
Language: Python
Author: CodeByTushu
"""
from typing import List
class Solution:
def uniformArray(self, nums1: List[int]) -> bool:
odd_count = 0
even_count = 0
for x in nums1:
if x % 2 == 0:
even_count += 1
else:
odd_count += 1
all_even = (odd_count == 0 or odd_count >= 2)
all_odd = (even_count == 0 or odd_count >= 1)
return all_even or all_odd
/**
* Problem: LeetCode 3875 - Construct Uniform Parity Array I
* Difficulty: Easy
* Language: C++
* Author: CodeByTushu
*/
#include <vector>
using namespace std;
/**
* Problem: LeetCode 3875 - Construct Uniform Parity Array I
* Difficulty: Easy
* Language: C++
* Author: CodeByTushu
*/
class Solution {
public:
bool uniformArray(vector<int>& nums1) {
int oddCount = 0, 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;
}
};
/**
* Problem: LeetCode 3875 - Construct Uniform Parity Array I
* Difficulty: Easy
* Language: JavaScript
* Author: CodeByTushu
*/
var uniformArray = function(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;
};