Array 3353. Minimum Total Operations ¶ Time: $O(n)$ Space: $O(1)$ C++JavaPython 1 2 3 4 5 6 7 8 9 10class Solution { public: int minOperations(vector<int>& nums) { int ans = 0; for (int i = 1; i < nums.size(); ++i) if (nums[i] != nums[i - 1]) ++ans; return ans; } }; 1 2 3 4 5 6 7 8 9class Solution { public int minOperations(int[] nums) { int ans = 0; for (int i = 1; i < nums.length; ++i) if (nums[i] != nums[i - 1]) ++ans; return ans; } } 1 2 3class Solution: def minOperations(self, nums: list[int]) -> int: return sum(a != b for a, b in itertools.pairwise(nums))