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;
}
}

相似题目

参考资料

LeetCode 718. 最长重复子数组(Maximum Length of Repeated Subarray)的更多相关文章

  1. [Swift]LeetCode718. 最长重复子数组 | Maximum Length of Repeated Subarray

    Given two integer arrays A and B, return the maximum length of an subarray that appears in both arra ...

  2. Java实现 LeetCode 718 最长重复子数组(动态规划)

    718. 最长重复子数组 给两个整数数组 A 和 B ,返回两个数组中公共的.长度最长的子数组的长度. 示例 1: 输入: A: [1,2,3,2,1] B: [3,2,1,4,7] 输出: 3 解释 ...

  3. leetcode 718. 最长重复子数组

    问题描述 给两个整数数组 A 和 B ,返回两个数组中公共的.长度最长的子数组的长度. 示例: 输入: A: [1,2,3,2,1] B: [3,2,1,4,7] 输出:3 解释: 长度最长的公共子数 ...

  4. 【LeetCode】718. Maximum Length of Repeated Subarray 解题报告(Python)

    [LeetCode]718. Maximum Length of Repeated Subarray 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxu ...

  5. Week 7 - 714. Best Time to Buy and Sell Stock with Transaction Fee & 718. Maximum Length of Repeated Subarray

    714. Best Time to Buy and Sell Stock with Transaction Fee - Medium Your are given an array of intege ...

  6. [LeetCode]Maximum Length of Repeated Subarray

    Maximum Length of Repeated Subarray: Given two integer arrays A and B, return the maximum length of ...

  7. 718. Maximum Length of Repeated Subarray

    Given two integer arrays A and B, return the maximum length of an subarray that appears in both arra ...

  8. LC 718. Maximum Length of Repeated Subarray

    Given two integer arrays A and B, return the maximum length of an subarray that appears in both arra ...

  9. [LeetCode] 718. Maximum Length of Repeated Subarray 最长的重复子数组

    Given two integer arrays A and B, return the maximum length of an subarray that appears in both arra ...

随机推荐

  1. Linux 组的管理

    一.Linux组基本介绍 在Linux中每个用户必须属于一个组,不能独立于组外.在Linux中每个文件有所有者,所在组,其他组的概念 1)所有者 2)所在组 3)其他组 4)改变用户的所在组 二.文件 ...

  2. tensorflow中的函数获取Tensor维度的两种方法:

    获取Tensor维度的两种方法: Tensor.get_shape() 返回TensorShape对象, 如果需要确定的数值而把TensorShape当作list使用,肯定是不行的. 需要调用Tens ...

  3. #C++初学记录(判断子串#数学结合)

    A Count Task Problem Description Count is one of WNJXYK's favorite tasks. Recently, he had a very lo ...

  4. CEF3开发者系列之Cookies管理和共享<转>

    原帖地址:https://www.cnblogs.com/guolixiucai/p/6994559.html 涉及网页登录相关的技术,Cookies肯定是忽略不了的.由于项目的需要,要做一个双核的产 ...

  5. vim脚本判断操作系统

    Linux 和 Windows 通用配置 其实在配置文件中是可以通过逻辑代码判断平台做条件处理的,这样就可以实现一个配置文件两个个平台下共用了,判断逻辑如下: " ============= ...

  6. composer Changed current directory to没反应

    根据官方手册执行composer global require "laravel/installer" 显示Changed current directory to C:/User ...

  7. 微信jaapi签名

    public WeiXinJsSignature(string weixinUrl) { //string url = ConfigurationManager.AppSettings["U ...

  8. Flutter Wrap 组件实现流布局

    Wrap 可以实现流布局,单行的 Wrap 跟 Row 表现几乎一致,单列的 Wrap 则跟 Row 表 现几乎一致.但 Row 与 Column 都是单行单列的,Wrap 则突破了这个限制,main ...

  9. consul_nginx_uprsync动态负载均衡

    consul_nginx_uprsync动态负载均衡 环境准备: 原理描述: 将Nginx的负载均衡后端服务器配置信息写入consul的接口中,upsync插件通过读取consul的配置,然后持久化到 ...

  10. 安装好oracle后如何使用PLSQL连接【我】

    简单的说: 一.如果你本地安装的是32位的Oracle,可以直接在PLSQl中配置oracle安装路径下的相关目录文件,直接启动PLSQL 二.如果你本地安装的是64位的Oracle或者oracle服 ...