Skip to content

Latest commit

 

History

History
92 lines (51 loc) · 1.69 KB

3201-find-the-maximum-length-of-valid-subsequence-i.adoc

File metadata and controls

92 lines (51 loc) · 1.69 KB

3201. Find the Maximum Length of Valid Subsequence I

{leetcode}/problems/find-the-maximum-length-of-valid-subsequence-i/[LeetCode - 3201. Find the Maximum Length of Valid Subsequence I ^]

You are given an integer array nums. A <span data-keyword="subsequence-array">subsequence sub of nums with length x is called valid if it satisfies:

  • (sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == …​ == (sub[x - 2] + sub[x - 1]) % 2.

Return the length of the longest valid subsequence of nums.

A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.

Example 1:

<div class="example-block"> Input: <span class="example-io">nums = [1,2,3,4]

Output: <span class="example-io">4

Explanation:

The longest valid subsequence is [1, 2, 3, 4].

Example 2:

<div class="example-block"> Input: <span class="example-io">nums = [1,2,1,1,2,1,2]

Output: 6

Explanation:

The longest valid subsequence is [1, 2, 1, 2, 1, 2].

Example 3:

<div class="example-block"> Input: <span class="example-io">nums = [1,3]

Output: <span class="example-io">2

Explanation:

The longest valid subsequence is [1, 3].

Constraints:

  • 2 ⇐ nums.length ⇐ 2 * 105

  • 1 ⇐ nums[i] ⇐ 107

思路分析

一刷
link:{sourcedir}/_3201_FindTheMaximumLengthOfValidSubsequenceI.java[role=include]

参考资料