Skip to content

Commit 3178798

Browse files
committedJul 31, 2024·
add 2900
1 parent 4ff9abb commit 3178798

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed
 

‎paginated_contents/algorithms/3rd_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
| 2965 | [Find Missing and Repeated Values](https://leetcode.com/problems/find-missing-and-repeated-values/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2965.java) | | Easy |
77
| 2942 | [Find Words Containing Character](https://leetcode.com/problems/find-words-containing-character/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2942.java) | | Easy |
88
| 2937 | [Make Three Strings Equal](https://leetcode.com/problems/make-three-strings-equal/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2937.java) | | Easy |
9+
| 2900 | [Longest Unequal Adjacent Groups Subsequence I](https://leetcode.com/problems/longest-unequal-adjacent-groups-subsequence-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2900.java) | | Easy |
910
| 2899 | [Last Visited Integers](https://leetcode.com/problems/last-visited-integers/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2899.java) | | Easy |
1011
| 2894 | [Divisible and Non-divisible Sums Difference](https://leetcode.com/problems/divisible-and-non-divisible-sums-difference/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2894.java) | | Easy |
1112
| 2873 | [Maximum Value of an Ordered Triplet I](https://leetcode.com/problems/maximum-value-of-an-ordered-triplet-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2873.java) | | Easy |

‎src/main/java/com/fishercoder/common/utils/CommonUtils.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ public static void print(int num) {
7272
}
7373

7474
public static void print(List<String> list) {
75-
System.out.println("----------------------------------------------------");
75+
System.out.println("List of string is: ");
7676
for (String str : list) {
7777
System.out.print(str + ", ");
7878
}
79-
System.out.println();
79+
System.out.println("\n----------------------------------------------------");
8080
}
8181

8282
public static void println(String message) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.fishercoder.solutions.thirdthousand;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class _2900 {
7+
public static class Solution1 {
8+
public List<String> getLongestSubsequence(String[] words, int[] groups) {
9+
int longest = 0;
10+
List<String> ans = new ArrayList<>();
11+
for (int i = 0; i < words.length; i++) {
12+
List<String> candidate = new ArrayList<>();
13+
candidate.add(words[i]);
14+
int lastBit = groups[i];
15+
for (int j = i + 1; j < words.length; j++) {
16+
if (groups[j] != lastBit) {
17+
candidate.add(words[j]);
18+
lastBit = groups[j];
19+
}
20+
}
21+
if (candidate.size() > longest) {
22+
longest = candidate.size();
23+
ans = candidate;
24+
}
25+
}
26+
return ans;
27+
}
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fishercoder.thirdthousand;
2+
3+
import com.fishercoder.solutions.thirdthousand._2900;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
7+
import java.util.Arrays;
8+
9+
import static org.junit.jupiter.api.Assertions.assertEquals;
10+
11+
public class _2900Test {
12+
private static _2900.Solution1 solution1;
13+
14+
@BeforeEach
15+
public void setup() {
16+
solution1 = new _2900.Solution1();
17+
}
18+
19+
@Test
20+
public void test1() {
21+
assertEquals(Arrays.asList("s", "l", "r", "ypp", "ev", "fv", "qzk", "xlr", "w", "v"),
22+
solution1.getLongestSubsequence(
23+
new String[]{"s", "l", "djl", "euy", "r", "lur", "u", "ypp", "ev", "fv", "we", "qzk", "q", "xlr", "w", "wc", "a", "sd", "o", "x", "v"},
24+
new int[]{0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1}));
25+
}
26+
27+
}

0 commit comments

Comments
 (0)
Please sign in to comment.