classSolution { public: intminOperations(vector<int>& nums, int x){ int n = nums.size(), ans = 0x3f3f3f3f; int j = n - 1, sum = 0; while (j >= 0 && sum < x) { sum += nums[j]; --j; } ++j; if (sum == x) ans = n - j; for (int i = 0; i < n; ++i) { sum += nums[i]; while (j < n && sum > x) { sum -= nums[j]; ++j; } if (sum == x && j > i) { ans = min(ans, i + 1 + n - j); } } return ans == 0x3f3f3f3f ? -1 : ans; } };