Skip to content

Commit beb21e0

Browse files
authored
Create 2900. Longest Unequal Adjacent Groups Subsequence I (#794)
2 parents 2f19517 + e56fdfd commit beb21e0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public:
3+
static vector<string> getLongestSubsequence(vector<string>& words, vector<int>& groups) {
4+
const int n=groups.size();
5+
int prev=groups[0];
6+
int len=1;
7+
for(int i=1, j=1; i<n; i++){
8+
while(i<n && prev==groups[i])
9+
i++;
10+
if (i<n) {
11+
words[j++]=words[i];
12+
len++;
13+
prev=groups[i];
14+
}
15+
}
16+
words.resize(len);
17+
return words;
18+
}
19+
};

0 commit comments

Comments
 (0)