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 find the length of the longest subarray whose product is positive by leetcode

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

Share

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

This article mainly introduces how leetcode calculates the length of the longest sub-array whose product is a positive number, which can be used for reference by interested friends. I hope you can learn a lot after reading this article.

Give you an integer array nums, please find out the length of the longest subarray whose product is positive.

A subarray of an array is an array of zero or more consecutive numbers in the original array.

Please return the length of the longest subarray whose product is positive.

Example 1:

Input: nums = [1mai mai 2mi mi 3jue 4]

Output: 4

Explanation: the product of the array itself is a positive number with a value of 24.

Example 2:

Input: nums = [0je 1m m m 2m m 3m m el 4]

Output: 3

Explanation: the subarray whose longest product is positive is [1], and the product is 6.

Note that we cannot include 0 in the subarray, because the product is 0, not a positive number.

Example 3:

Input: nums = [- 1 flint 2meme 3jin0jue 1]

Output: 2

Explanation: the longest subarray whose product is positive is [- 1] or [- 2].

Example 4:

Input: nums = [- 1BI 2]

Output: 1

Example 5:

Input: nums = [1, 2, 3, 5, 5, 6, 4, 0, 10]

Output: 4

Tip:

one

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: 280

*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