You are given an integer array nums. In one operation, you can add or subtract 1 from any element of nums.
Return the minimum number of operations to make all elements of nums divisible by 3.
class Solution {
public:
int minimumOperations(vector<int>& nums) {
int ans =0;
for(int i=0;i<nums.size();i++)
{
int tmp=0;
tmp=min(3-nums[i]%3,nums[i]%3);
ans += tmp;
}
return ans;
}
};