classSolution{public:intcountPartitions(std::vector<int>&nums){// If we add the same number in the left subarray and remove it from the// right subarray, then the difference remains the same parity. So, just// return the number of ways to partition the array into two subarrays when// the array sum is even.returnaccumulate(nums.begin(),nums.end(),0)%2==0?nums.size()-1:0;}};
123456789
classSolution{publicintcountPartitions(int[]nums){// If we add the same number in the left subarray and remove it from the// right subarray, then the difference remains the same parity. So, just// return the number of ways to partition the array into two subarrays when// the array sum is even.returnArrays.stream(nums).sum()%2==0?nums.length-1:0;}}
1234567
classSolution:defcountPartitions(self,nums:list[int])->int:# If we add the same number in the left subarray and remove it from the# right subarray, then the difference remains the same parity. So, just# return the number of ways to partition the array into two subarrays when# the array sum is even.returnlen(nums)-1ifsum(nums)%2==0else0