Skip to content

Commit df6af3c

Browse files
committedJul 6, 2024·
add 3206
1 parent e2e7131 commit df6af3c

File tree

2 files changed

+27
-0
lines changed
  • paginated_contents/algorithms/4th_thousand
  • src/main/java/com/fishercoder/solutions/firstthousand

2 files changed

+27
-0
lines changed
 

‎paginated_contents/algorithms/4th_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
| # | Title | Solutions | Video | Difficulty | Tag
22
|------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|------------|----------------------------------------------------------------------
3+
| 3206 | [Alternating Groups I](https://leetcode.com/problems/alternating-groups-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3206.java) | | Easy |
34
| 3200 | [Maximum Height of a Triangle](https://leetcode.com/problems/maximum-height-of-a-triangle/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3200.java) | | Easy |
45
| 3199 | [Count Triplets with Even XOR Set Bits I](https://leetcode.com/problems/count-triplets-with-even-xor-set-bits-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3199.java) | | Easy |
56
| 3196 | [Maximize Total Cost of Alternating Subarrays](https://leetcode.com/problems/maximize-total-cost-of-alternating-subarrays/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3196.java) | | Medium |DP
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.fishercoder.solutions.firstthousand;
2+
3+
public class _3206 {
4+
public static class Solution1 {
5+
public int numberOfAlternatingGroups(int[] colors) {
6+
int result = 0;
7+
int len = colors.length;
8+
for (int i = 0; i < len; i++) {
9+
if (i == 0) {
10+
if (colors[i] != colors[len - 1] && colors[i] != colors[i + 1]) {
11+
result++;
12+
}
13+
} else if (i < len - 1) {
14+
if (colors[i] != colors[i - 1] && colors[i] != colors[i + 1]) {
15+
result++;
16+
}
17+
} else {
18+
if (colors[i] != colors[i - 1] && colors[i] != colors[0]) {
19+
result++;
20+
}
21+
}
22+
}
23+
return result;
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)
Please sign in to comment.