3201. 找出有效子序列的最大长度 I

3201. 找出有效子序列的最大长度 I


题目链接:3201. 找出有效子序列的最大长度 I

代码如下:

class Solution {
public:
	int maximumLength(vector<int>& nums) {
		int res = 0;
		vector<vector<int>> f(2, vector<int>(2));
		for (int x : nums) {
			x %= 2;
			for (int y = 0;y < 2;y++) {
				f[y][x] = f[x][y] + 1;
				res = max(res, f[y][x]); // 更新最大长度
			}
		}
		return res;
	}
};

你可能感兴趣的:(c++)