Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to realize the longest continuous increasing sequence by java

Shulou Source: shulou.com Published: 2022-06-01 01:12:41 10月25日 Update

This article mainly introduces java how to achieve the longest continuous increasing sequence, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Topic description

Given an unsorted array of integers, find the longest and continuous increment sequence.

Example 1:

Output: 3 explanation: the longest continuous increasing sequence is [1mem3pyrine 5], the length is 3. Although it is also a subsequence of ascending order, it is not continuous because 5 and 7 are separated by 4 in the original array.

Example 2:

Output: 1 explanation: the longest continuous increasing sequence is [2], and the length is 1.

Note: the array length will not exceed 10000.

The idea of solving the problem

Tags: traversing

Process:

Count is the current element peak, and ans is the maximum peak.

Initialize count = 1

Traversal starts from position 0, and the ergodic time determines whether it is increasing according to the state of the elements before and after. If it increases, the count++, decreases, then count=1.

If count > ans, update ans

Until the end of the cycle

Time complexity: O (N)

Code class Solution {public int findLengthOfLCIS (int [] nums) {if (nums.length ans? Count: ans;} return ans;}} Thank you for reading this article carefully. I hope the article "how to achieve the longest continuous increasing sequence of java" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Sequence longest article array length element peak example interpretation input output complexity maximum code value location interest ascending order and complexity Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Docker vpn Shulou Technology Apple