当前位置:网站首页>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;
}
边栏推荐
- Different subsequence problems I
- 有哪些劵商推荐?现在在线开户安全么?
- Reading graph augmentations to learn graph representations (lg2ar)
- Module externe unity3d anyportrait 2D Skeleton Animation
- Open world mecha games phantom Galaxy
- Solid and ambient colors
- go语言中的私聊功能处理
- Installing MySQL on Ubuntu
- Restfultoolkitx of idea utility plug-in -- restful interface debugging
- BS-GX-016基于SSM实现教材管理系统
猜你喜欢
![[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]

Unity: the referenced script (unknown) on this behavior is missing“

WordPress collection plug-ins are recommended to be free collection plug-ins

通过两个stack来实现Queue

树莓派初步使用

go语言中的私聊功能处理

Open world mecha games phantom Galaxy

微信小程序自动生成打卡海报

The user adds a timer function in the handler () goroutine. If it times out, it will be kicked out

Microservices and container choreography in go
随机推荐
[mixed programming JNI] Part 12 jnaerator
ASP. Net core create MVC project upload file (buffer mode)
Share three methods of automatic summation in Excel
主从复制系统设计
树莓派初步使用
电子协会 C语言 1级 31 、 计算线段长度
用户在hander()goroutine,添加定时器功能,超时则强踢出
Unity: 脚本缺失 “The referenced script (Unknown) on this Behaviour is missing!“
Do an online GIF synthesis service at no cost
typora设置标题自动编号
固有色和环境色
What are the test case design methods?
运筹说 第66期|贝尔曼也有“演讲恐惧症”?
The client implements client Go client type definition connection
想买股票请问在券商公司的哪里开户佣金低更安全
Module externe unity3d anyportrait 2D Skeleton Animation
UnityEditor編輯器擴展-錶格功能
Unityeditor Editor Extension - table function
开放世界机甲游戏-Phantom Galaxies
Weaving dream collection plug-ins are recommended to be free collection plug-ins