Leetcode 算法设计 第十四周
来源:互联网 发布:java常见的接口 编辑:程序博客网 时间:2024/04/29 17:21
718. Maximum Length of Repeated Subarray
Given two integer arrays A and B, return the maximum length of an subarray that appears in both arrays.
Example 1:
Input:
A: [1,2,3,2,1]
B: [3,2,1,4,7]
Output: 3
Explanation:
The repeated subarray with maximum length is [3, 2, 1].
题目大意
找出两数组中最长相同子数组
我的解答
class Solution {public: int findLength(vector<int>& A, vector<int>& B) { int m = A.size(); int n = B.size(); int result = 0; vector<vector<int>>dp(m+1,vector<int>(n+1,0)); for(int i = 1; i <= m; i++){ for(int j = 1; j <= n; j++){ if(A[i-1]==B[j-1]){ dp[i][j] = dp[i-1][j-1]+1; result = max(result,dp[i][j]); } } } return result; }};
阅读全文
0 0
- Leetcode 算法设计 第十四周
- Leetcode 算法设计 第十四周
- Leetcode 算法设计 第十四周
- Leetcode 算法设计 第十四周
- Leetcode 算法习题 第十四周
- 第十四周LeetCode算法题两道
- Leetcode 算法习题 第十四周
- Leetcode 算法习题 第十四周
- Leetcode 算法习题 第十四周
- Leetcode 算法习题 第十四周
- Leetcode 算法习题 第十四周
- 算法设计与应用基础:第十四周
- 算法分析与设计第十四周
- leetcode-python 第十四周
- leetcode-第十四周
- 第十四周leetcode题
- 第十四周LeetCode
- 第十四周LeetCode
- Docker 安装 RabbitMQ 集群
- liunx常用命令-01
- Locating Restriction Sites
- strong对象,替换 replace,将字符串1转化为字符串2
- 问题解决:DuplicateKeyException: a different object with the same identifier value
- Leetcode 算法设计 第十四周
- WebService返回XML文件自定义格式
- codeforces 897 A. Scarborough Fair 【暴力】
- 用两栈和两队列实现简易停车场管理系统
- tornado4.5.2HTTP请求及响应流程
- Docker 安装 MongoDB 3.x
- 回溯法-5.3批处理作业调度
- cmd命令
- (一)python的可变与不可变数据类型