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. vue-d2admin-axios异步请求登录,先对比一下Jquery ajax, Axios, Fetch区别

    先说一下对比吧 Jquery ajax, Axios, Fetch区别之我见 引言 前端技术真是一个发展飞快的领域,我三年前入职的时候只有原生XHR和Jquery ajax,我们还曾被JQuery 1 ...

  2. 性能测试JMeter应用篇---同线程组、跨线程组实现token共用

    方式一:将token值取出,设为全局变量,同线程组内可共用token值 1.登录请求如下: 2.从登录请求返回json字符串中提取token值,保存为变量token_0: 3.将token设置为全局变 ...

  3. Intellij IDEA 从入门到上瘾 图文教程

    1. IDEA VS Eclipse 核心术语比较 ​ 由下图可见:两者最大的转变就在于工作空间概念的转变,并且在IDEA当中,Project和 Module是作为两个不同的概念,对项目结构是具有重大 ...

  4. Samba文件共享服务设置

    SMB的主程序 smbd:SMB-TCP139,CIFS-TCP445 nmbd:NetBios-UDP137,138 SMB主程序对应的两个服务 /etc/init.d/smb /etc/init. ...

  5. ciscn2019华北赛区半决赛day2_web1题解

    比赛结束以后采用非官方复现平台做的题,和比赛题有轻微不同,比赛中存放flag的table是ctf,这里是flag. 题目地址 buuoj.cn 解题过程 题目中只有一个页面,需要提交id. id为1, ...

  6. 三大框架 之 OGNL表达式

    目录 OGNL 什么是OGNL OGNL与EL表达式对比 OGNL功能 OGNL使用要素 OGNL入门 java程序使用ognl struts2中使用ONGL OGNL 什么是OGNL OGNL是Ob ...

  7. 【深度学习】关于Adam

    版权声明:本文为博主原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/weixin_31866177/articl ...

  8. I.MX6 dts 在哪里、怎么编译【转】

    本文转载自:https://blog.csdn.net/wangliang888888/article/details/78349224 一.参考文档: 1. [i.MX] 修改了dts之后,如何重新 ...

  9. linux下的/dev/shm/及对Oracle 的影响

    一./dev/shm/介绍: /dev/shm/是linux下一个非常有用的目录,因为这个目录不在硬盘上,而是在内存里.因此在linux下,就不需要大费周折去建ramdisk,直接使用/dev/shm ...

  10. nginx: [emerg] unknown directive "stub_status" in /home/oscf/nginx/conf/conf.d/ngx_metric.conf

    解压安装过程命令如下: cd /home/oscf #该目录下有nginx压缩包 mkdir nginx tar -zxvf nginx-1.16.0.tar.gz cd nginx-1.16.0 . ...