leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE |

commit7ee76da2829e83e82c685c0b8271ac2a81ef3a6c
parent8adc9eed81d0c940bfce3e1f9fc8577c411830b2
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateSun, 18 Aug 2024 11:16:08 +0200

1 Random Problem

Diffstat:
AProblems/3191.cpp|+++++++++++++++++
MREADME.md|+

2 files changed, 18 insertions(+), 0 deletions(-)


diff --git a/Problems/3191.cpp b/Problems/3191.cpp

@@ -0,0 +1,17 @@

class Solution {
public:
int minOperations(vector<int> &nums) const {
const int n = size(nums);
int res = 0;
for (int i = 0; i < n - 2; i++) {
if (nums[i]) continue;
nums[i + 1] = !nums[i + 1];
nums[i + 2] = !nums[i + 2];
res++;
}
if (!nums[n - 2] || !nums[n - 1]) return -1;
return res;
}
};

diff --git a/README.md b/README.md

@@ -1316,6 +1316,7 @@ for solving problems.

| 3111 | Medium | [Minimum Rectangles to Cover Points](Problems/3111.cpp) |
| 3159 | Medium | [Find Occurrences of an Element in an Array](Problems/3159.cpp) |
| 3190 | Easy | [Find Minimum Operations to Make All Elements Divisible by Three](Problems/3190.cpp) |
| 3191 | Medium | [Minimum Operations to Make Binary Array Elements Equal to One I](Problems/3191.cpp) |
| 3192 | Medium | [Minimum Operations to Make Binary Array Elements Equal to One II](Problems/3192.cpp) |
| 3195 | Medium | [Find the Minimum Area to Cover All Ones I](Problems/3195.cpp) |
| 3211 | Medium | [Generate Binary Strings Without Adjacent Zeros](Problems/3211.cpp) |