Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the longest continuous increasing sequence by java

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report