当前位置:网站首页>Leetcode 718. 最长重复子数组(暴力枚举,待解决)
Leetcode 718. 最长重复子数组(暴力枚举,待解决)
2022-06-26 23:08:00 【我不是萧海哇~~~~】
给两个整数数组 nums1 和 nums2 ,返回 两个数组中 公共的 、长度最长的子数组的长度 。
示例 1:
输入:nums1 = [1,2,3,2,1], nums2 = [3,2,1,4,7]
输出:3
解释:长度最长的公共子数组是 [3,2,1] 。
示例 2:
输入:nums1 = [0,0,0,0,0], nums2 = [0,0,0,0,0]
输出:5
提示:
- 1 <= nums1.length, nums2.length <= 1000
- 0 <= nums1[i], nums2[i] <= 100
Code:
int findLength(vector<int>& nums1, vector<int>& nums2) {
pair<map<vector<int>, int>::iterator, bool> ret;
map<vector<int>,int>mymap;
for(int l=0;l<nums1.size();l++)
{
for(int i=1+l;i<=nums1.size();i++)
{
vector<int>vec;
for(int j=l;j<i;j++)
{
// cout<<nums1[j]<< " ";
vec.push_back(nums1[j]);
}
mymap.insert(pair<vector<int>,int>(vec,0));
// cout<<endl;
}
}
int maxlen=0;
for(int l=0;l<nums2.size();l++)
{
// for(int i=1+l;i<=nums2.size();i++)
for(int i=nums2.size();i>=1+l;i--)
{
vector<int>vec;
for(int j=l;j<i;j++)
{
cout<<nums2[j]<< " ";
vec.push_back(nums2[j]);
}
cout<<endl;
if(mymap.find(vec)!=mymap.end())
{
maxlen=max(maxlen,(int)vec.size());
}
}
}
return maxlen;
}
边栏推荐
- 【混合编程jni 】第六篇之native 中字符串和数组的操作
- go语言的服务发现、存储引擎、静态网站
- go语言的爬虫和中间件
- Unity: 脚本缺失 “The referenced script (Unknown) on this Behaviour is missing!“
- [kotlin] keyword suspend learning of thread operation and async understanding
- 【强基计划】数学与物理竞赛中的微积分部分视频
- ASP. Net core create MVC project upload file (buffer mode)
- 6.24 learning content
- Weaving dream collection plug-ins are recommended to be free collection plug-ins
- 【测试】最火的测试开发学习路线内容再次大更新,助力通关大厂测开
猜你喜欢
![[fundamentals of image processing] GUI image histogram equalization system based on MATLAB [including Matlab source code 1924]](/img/8a/f5847eef7318f3db54aa2d4405b06a.jpg)
[fundamentals of image processing] GUI image histogram equalization system based on MATLAB [including Matlab source code 1924]

论文解读(LG2AR)《Learning Graph Augmentations to Learn Graph Representations》

FPGA -vga display

typora设置标题自动编号

让敏捷回归本源——读《敏捷整洁之道》有感

go语言的爬虫和中间件

Three solutions for improving embedded software development environment

ASP.Net Core创建MVC项目上传文件(缓冲方式)

The user adds a timer function in the handler () goroutine. If it times out, it will be kicked out
![Selenium电脑上怎么下载-Selenium下载和安装图文教程[超详细]](/img/ec/1c324dcf38d07742a139aac2bab02e.png)
Selenium电脑上怎么下载-Selenium下载和安装图文教程[超详细]
随机推荐
【强基计划】数学与物理竞赛中的微积分部分视频
电子协会 C语言 1级 30 、 等差数列末项计算
简单测试轻量级表达式计算器Flee
[fundamentals of image processing] GUI image curve adjustment system based on MATLAB [including Matlab source code 1923]
Unity初学者肯定能用得上的50个小技巧
UnityEditor编辑器扩展-表格功能
微信小程序自动生成打卡海报
开放世界机甲游戏-Phantom Galaxies
不同的子序列问题I
BS-GX-016基于SSM实现教材管理系统
UnityEditor編輯器擴展-錶格功能
Weaving dream collection plug-ins are recommended to be free collection plug-ins
Flashtext, a data cleaning tool, has directly increased the efficiency by dozens of times
DAST 黑盒漏洞扫描器 第五篇:漏洞扫描引擎与服务能力
简述unity的模型动画功能
golang语言的开发学习路线
Unity animation knowledge of Art
Which securities dealers recommend? Is it safe to open an account online now?
leetcode 1143. Longest Commom Subsequence 最长公共子序列(中等)
Smartbi gives you a piece to play with Boston matrix