8000 add 3038 · githubniraj/Leetcode@a2c32b3 · GitHub
[go: up one dir, main page]

Skip to content

Commit a2c32b3

Browse files
add 3038
1 parent 8a76de1 commit a2c32b3

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _3038 {
4+
public static class Solution1 {
5+
public int maxOperations(int[] nums) {
6+
int maxOps = 0;
7+
if (nums == null || nums.length < 2) {
8+
return maxOps;
9+
}
10+
maxOps++;
11+
int sum = nums[0] + nums[1];
12+
for (int i = 2; i < nums.length - 1; i += 2) {
13+
if (nums[i] + nums[i + 1] == sum) {
14+
maxOps++;
15+
} else {
16+
break;
17+
}
18+
}
19+
return maxOps;
20+
}
21+
}
22+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._3038;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
9+
public class _3038Test {
10+
private static _3038.Solution1 solution1;
11+
private static int[] nums;
12+
13+
@BeforeEach
14+
public void setup() {
15+
solution1 = new _3038.Solution1();
16+
}
17+
18+
@Test
19+
public void test1() {
20+
nums = new int[]{2, 2, 3, 2, 4, 2, 3, 3, 1, 3};
21+
assertEquals(1, solution1.maxOperations(nums));
22+
}
23+
24+
}

0 commit comments

Comments
 (0)
0