Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”

This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money.

Like it and see. Make it a habit. Wechat search [a coding] follow this programmer who is struggling in the Internet.

This article is collected on Github – Technical expert Training, which contains my learning route, series of articles, interview question bank, self-study materials, e-books, etc.


See how I can solve this problem using and lookup sets! (Dog’s head saved)

— Leetcode

preface

Hello, everyone. I’m One.

Confused algorithm, rarely confused

Question

674. Longest continuously increasing sequence

Difficulty: Easy

Given an unsorted array of integers, find the longest continuously increasing subsequence and return the length of that sequence.

Continuously increasing subsequences can be determined by two subscripts L and r (l < r), if for every L <= I < r, nums[I] < nums[I + 1], Then the subsequence [NUMs [L], NUMs [L + 1]…, NUMs [r-1], NUMs [r]] is a continuous increasing subsequence.

Example 1:

Input: nums = [1,3,5,4,7] output: 3 explanation: the longest continuously increasing sequence is [1,3,5] and has a length of 3.Copy the code

Although [1,3,5,7] is also an ascending subsequence, it is not continuous because 5 and 7 are separated by 4 in the original array. Example 2:

Input: nums = [2,2,2,2] Output: 1 Explanation: The longest continuously increasing sequence is [2], of length 1.Copy the code

Solution

The same thing as the largest number of consecutive ones

The maximum number of consecutive 1s

Code

All LeetCode codes have been synchronized to Github

Welcome to star

/ * * *@authorA coding * /
class Solution {
    public int findLengthOfLCIS(int[] nums) {
        if(nums.length <= 1)
            return nums.length;
        int ans = 1;
        int count = 1;
        for(int i=0; i<nums.length-1; i++) {if(nums[i+1] > nums[i]) {
                count++;
            } else {  
                count = 1;
            }
            ans = count > ans ? count : ans;
        }
        returnans; }}Copy the code

Result

Complexity analysis

  • Time complexity: O(N)

Last

One foot is difficult to go, one hand is difficult to sing, a person’s power is limited after all, a person’s journey is doomed to be lonely. When you set a good plan, with full of blood ready to set out, must find a partner, and Tang’s monk to the West, the master and his disciples four people united as one to pass the ninety-eight difficult. So,

If you want to get into a big factory,

To learn data structures and algorithms,

If you want to keep brushing,

To have a group of like-minded people,

Please join the team to brush the questions