Skip to content

Commit 0cb7395

Browse files
committed
feat(leetcode): add No.3038
1 parent 519a840 commit 0cb7395

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// https://leetcode.com/problems/maximum-number-of-operations-with-the-same-score-i/description/
2+
// algorithms
3+
// Easy (48.6%)
4+
// Total Accepted: 21.1K
5+
// Total Submissions: 43.5K
6+
7+
8+
class Solution {
9+
10+
public int maxOperations(int[] nums) {
11+
int res = 1;
12+
int opScore = nums[0] + nums[1];
13+
int len = nums.length;
14+
15+
for (int i = 2; i < len; i += 2) {
16+
if (i == len - 1) {
17+
break;
18+
}
19+
20+
if (nums[i] + nums[i + 1] != opScore) {
21+
break;
22+
}
23+
24+
res += 1;
25+
}
26+
27+
return res;
28+
}
29+
30+
}

0 commit comments

Comments
 (0)