leetcode 718( Maximum Length of Repeated Subarray)
来源:互联网 发布:wp10记录仪软件 编辑:程序博客网 时间:2024/06/04 19:16
1.题目描述:给定两个数组,在两个数组中,返回包含相同元素最多的数组的长度。
例子:
A: [1,2,3,2,1]
B: [3,2,1,4,7]
返回:3.
解释:在数组 A和B中最长的子数组为[3,2,1]长度为3.
2.代码:
class Solution{ public int findLength(int [] A, int [] B){ int res = 0; // java 中 int 默认值为0,需要前一个的值因此长度要比以前的数组大一 int [][] dp = new int[A.length+1][B.length+1]; for(int i = 0; i < A.length; i++){ for(int j = 0; j < B.length; j++){ if(A[i] == B[j]){ dp[i+1][j+1] = dp[i][j] +1; } res = Math.max(res, dp[i+1][j+1]); } } return res; }}
阅读全文
0 0
- leetcode 718( Maximum Length of Repeated Subarray)
- LeetCode #718 Maximum Length of Repeated Subarray
- Leetcode 718 Maximum Length of Repeated Subarray
- Leetcode 718. Maximum Length of Repeated Subarray
- Leetcode | Maximum Length of Repeated Subarray
- Leetcode | Maximum Length of Repeated Subarray
- LeetCode:Maximum Length of Repeated Subarray
- [leetcode]Maximum Length of Repeated Subarray
- Leetcode 718. Maximum Length of Repeated Subarray
- leetcode 718. Maximum Length of Repeated Subarray
- [LeetCode]718. Maximum Length of Repeated Subarray
- [LeetCode]Maximum Length of Repeated Subarray
- [LeetCode] 718. Maximum Length of Repeated Subarray
- [leetcode] 718. Maximum Length of Repeated Subarray
- LeetCode:Maximum Length of Repeated Subarray
- leetCode-Maximum Length of Repeated Subarray
- Leetcode:718. Maximum Length of Repeated Subarray
- LeetCode#718 Maximum Length of Repeated Subarray (week9)
- RASAC 入门
- DB2 SQL0668N Operation not allowed for reason code "7" on table
- bzoj 1827: [Usaco2010 Mar]gather 奶牛大集会
- oracle学习笔记
- C语言经典知识示例之01怎样确定float类型变量的有效数字个数
- leetcode 718( Maximum Length of Repeated Subarray)
- 【POJ
- mysql JDBC URL格式各个参数详解
- Target Sum
- 周中训练笔记15
- 求职互联网公司最需要注意的方面有什么
- Simplify Transfer Learning (简化迁移学习)
- nginx 常用配置
- Linux操作系统与实训教程实验四Linux系统管理