Skip to content

Commit fd58b48

Browse files
authored
Create maximum-number-of-operations-with-the-same-score-i.cpp
1 parent ffeda9a commit fd58b48

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
// array
5+
class Solution {
6+
public:
7+
int maxOperations(vector<int>& nums) {
8+
int result = 1;
9+
const int target = nums[0] + nums[1];
10+
for (int i = 2; i + 1 < size(nums); i += 2) {
11+
if (nums[i] + nums[i + 1] != target) {
12+
break;
13+
}
14+
++result;
15+
}
16+
return result;
17+
}
18+
};

0 commit comments

Comments
 (0)