2900: Longest-Unequal-Adjacent-Groups-Subsequence-I
Easy
You can basically just iterate through both words
and groups
, keeping track of the
previous
binary integer. While you are iterating, if
previous != groups[i]
, you can just push
words[i]
to the end of ans
and update
previous
.
Code:
class Solution {
public:
<string> getLongestSubsequence(vector<string>& words, vector<int>& groups) {
vector<string> ans;
vectorint previous = -1;
for (int i = 0; i < groups.size(); ++i)
{
if (previous != groups[i]) {
.push_back(words[i]);
ans= groups[i];
previous }
}
return ans;
}
};