Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to obtain the longest incremental subsequence by leetcode

Shulou Source: shulou.com Published: 2022-06-01 12:47:19 09月15日 Update

This article is about how leetcode can get the longest incremental subsequence. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Given an unsorted array of integers, find the number of the longest increasing subsequences.

Example 1:

Input: [1, 3, 5, 4, 7]

Output: 2

Explanation: there are two longest increasing subsequences, which are [1,3,4,7] and [1,3,5,7] respectively.

Example 2:

Input: [2, 2, 2, 2, 2, 2]

Output: 5

Explanation: the length of the longest incremental subsequence is 1, and there are 5 subsequences whose length is 1, so output 5.

Note: the given array length does not exceed 2000 and the result must be a 32-bit signed integer.

1. Define l [I] storage, with the longest increment subsequence length ending with nums [I], c [I] as the number.

2, the initialization condition is: 1 [0: len (nums)] = 1 c [0:len (nums) = 1]

3, for any j

Tags: Sequence longest length number output content array integer more example article explanation input good practical subscript two size that is the situation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Microsoft Shulou Technology Xiaomi MariaDB