首页
题库
面试
求职
学习
竞赛
More+
所有博客
搜索面经/职位/试题/公司
搜索
我要招人
去企业版
登录 / 注册
首页
>
试题广场
>
乘积为正数的最长连续子数组
[编程题]乘积为正数的最长连续子数组
热度指数:485
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 256M,其他语言512M
算法知识视频讲解
给定一个长度为 n 的整数数组,请你找出其中最长的乘积为正数的子数组长度。
子数组的定义是原数组中一定长度的连续数字组成的数组。
数据范围:
, 数组中的元素满足
示例1
输入
[1,2,3,-1,4]
输出
3
示例2
输入
[1,2,3,0,4]
输出
3
马上挑战
算法知识视频讲解
提交运行
算法知识视频讲解
添加笔记
求解答(0)
邀请回答
收藏(20)
分享
纠错
提交结果有问题?
5个回答
2篇题解
开通博客
姐姐的遮阳伞
发表于 2022-04-05 19:20:12
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型ArrayList
展开全文
氯化钠哈哈哈
发表于 2023-12-24 16:03:44
非动态规划思路: 以0为边界先将所有数据分块,然后对每个块进行遍历 找到每个块中第一个负数和最后一个负数 然后计算当前块中,左边界和最后一个负数之间的距离 与 右边界与第一个负数的距离,距离更大的就是当前块中的答案 最后在所有块中的答案中,找到最大数字,即最终答案 class
展开全文
问题信息
动态规划
难度:
5条回答
20收藏
721浏览
热门推荐
通过挑战的用户
查看代码
王小牛123
2022-09-16 09:21:26
西方不胜
2022-09-05 21:18:13
就,很有意思
2022-09-01 10:24:51
NepentheV
2022-08-24 12:20:18
半个西瓜半个夏
2022-08-23 22:29:54
相关试题
1.该校教师最多的是哪一年?( ...
资料分析
言语理解与表达
资料分析
评论
(1)
有同事不完成任务,影响力进度,你怎...
业务综合
评论
(1)
你身边有哪些人还没有使用滴滴,你认...
用户研究
评论
(1)
怎么做一个需求
需求分析
评论
(1)
A/B test场景问题,第一类错...
评论
(1)
扫描二维码,关注牛客网
意见反馈
下载牛客APP,随时随地刷题
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型ArrayList * @return int整型 */ public int findLongestSubArray (ArrayList
nums) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型vector * @return int整型 */ int findLongestSubArray(vector
& nums) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param nums int整型一维数组 # @return int整型 # class Solution: def findLongestSubArray(self , nums ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ public int findLongestSubArray (List
nums) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ function findLongestSubArray( nums ) { // write code here } module.exports = { findLongestSubArray : findLongestSubArray };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param nums int整型一维数组 # @return int整型 # class Solution: def findLongestSubArray(self , nums: List[int]) -> int: # write code here
package main //import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ func findLongestSubArray( nums []int ) int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @param numsLen int nums数组长度 * @return int整型 */ int findLongestSubArray(int* nums, int numsLen ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param nums int整型一维数组 # @return int整型 # class Solution def findLongestSubArray(nums) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ def findLongestSubArray(nums: Array[Int]): Int = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ fun findLongestSubArray(nums: IntArray): Int { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ public int findLongestSubArray (int[] nums) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ export function findLongestSubArray(nums: number[]): number { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ func findLongestSubArray ( _ nums: [Int]) -> Int { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ pub fn findLongestSubArray(&self, nums: Vec
) -> i32 { // write code here } }
[1,2,3,-1,4]
3
[1,2,3,0,4]
3