-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_2900.java
29 lines (27 loc) · 967 Bytes
/
_2900.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.fishercoder.solutions.thirdthousand;
import java.util.ArrayList;
import java.util.List;
public class _2900 {
public static class Solution1 {
public List<String> getLongestSubsequence(String[] words, int[] groups) {
int longest = 0;
List<String> ans = new ArrayList<>();
for (int i = 0; i < words.length; i++) {
List<String> candidate = new ArrayList<>();
candidate.add(words[i]);
int lastBit = groups[i];
for (int j = i + 1; j < words.length; j++) {
if (groups[j] != lastBit) {
candidate.add(words[j]);
lastBit = groups[j];
}
}
if (candidate.size() > longest) {
longest = candidate.size();
ans = candidate;
}
}
return ans;
}
}
}