您现在的位置是:主页 > news > 小宽带怎样做视频网站/衡阳网站建设公司

小宽带怎样做视频网站/衡阳网站建设公司

admin2025/5/11 7:48:06news

简介小宽带怎样做视频网站,衡阳网站建设公司,江西省建设厅官方网站,凡客诚品官网网址718. 最长重复子数组718. Maximum Length of Repeated Subarray 题目描述 给定一个含有 n 个正整数的数组和一个正整数 s,找出该数组中满足其和 ≥ s 的长度最小的连续子数组。如果不存在符合条件的连续子数组,返回 0。 LeetCode718. Maximum Length of …

小宽带怎样做视频网站,衡阳网站建设公司,江西省建设厅官方网站,凡客诚品官网网址718. 最长重复子数组718. Maximum Length of Repeated Subarray 题目描述 给定一个含有 n 个正整数的数组和一个正整数 s,找出该数组中满足其和 ≥ s 的长度最小的连续子数组。如果不存在符合条件的连续子数组,返回 0。 LeetCode718. Maximum Length of …

718. 最长重复子数组
718. Maximum Length of Repeated Subarray

题目描述
给定一个含有 n 个正整数的数组和一个正整数 s,找出该数组中满足其和 ≥ s 的长度最小的连续子数组。如果不存在符合条件的连续子数组,返回 0。

LeetCode718. Maximum Length of Repeated Subarray

示例:

输入: s = 7, nums = [2,3,1,2,4,3]
输出: 2
解释: 子数组 [4,3] 是该条件下的长度最小的连续子数组。

进阶:
如果你已经完成了 O(n) 时间复杂度的解法,请尝试 O(nlogn) 时间复杂度的解法。

Java 实现

class Solution {public int findLength(int[] A, int[] B) {if (A == null || A.length == 0 || B == null || B.length == 0) {return 0;}int m = A.length, n = B.length;int res = Integer.MIN_VALUE;int[][] dp = new int[m + 1][n + 1];for (int i = m - 1; i >= 0; i--) {for (int j = n - 1; j >= 0; j--) {dp[i][j] = A[i] == B[j] ? dp[i + 1][j + 1] + 1 : 0;res = Math.max(res, dp[i][j]);}}return res;}
}

相似题目

  • 209. 长度最小的子数组

参考资料

  • https://leetcode.com/problems/maximum-length-of-repeated-subarray/
  • https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray/

转载于:https://www.cnblogs.com/hglibin/p/10924592.html