当前位置:网站首页>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;
}
边栏推荐
- 运筹说 第66期|贝尔曼也有“演讲恐惧症”?
- Unity4.6 Download
- Smartbi gives you a piece to play with Boston matrix
- Centos7 compiling and installing redis
- Redcap is ready to come out. It is indispensable to build a "meta universe"
- Leetcode (763) -- dividing letter ranges
- 有哪些劵商推荐?现在在线开户安全么?
- Color matching and related issues
- 颜色搭配和相关问题
- 客户端实现client.go客户端类型定义连接
猜你喜欢

开放世界机甲游戏-Phantom Galaxies
![[fundamentals of image processing] GUI image curve adjustment system based on MATLAB [including Matlab source code 1923]](/img/e8/6342f2dc6e7f06a847852ce4b40719.jpg)
[fundamentals of image processing] GUI image curve adjustment system based on MATLAB [including Matlab source code 1923]

Operations research says that in issue 66, Behrman also has "speech phobia"?
![[mathematical modeling] spanning tree based on Matlab GUI random nodes [including Matlab source code 1919]](/img/0c/17efaaa2488451b6dd15d9db33eba7.jpg)
[mathematical modeling] spanning tree based on Matlab GUI random nodes [including Matlab source code 1919]

DAST 黑盒漏洞扫描器 第五篇:漏洞扫描引擎与服务能力

Color matching and related issues

您的连接不是私密连接
![[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]

Implement the queue through two stacks

The user adds a timer function in the handler () goroutine. If it times out, it will be kicked out
随机推荐
Module externe unity3d anyportrait 2D Skeleton Animation
【混合编程jni 】第九篇之Jni总结
[machine learning] - Introduction to vernacular and explanation of terms
Common configuration of jupyterlab
Unity3D插件 AnyPortrait 2D骨骼動畫制作
分享三种在Excel表格中自动求和的方法
电子协会 C语言 1级 31 、 计算线段长度
The client implements client Go client type definition connection
6.24 学习内容
[mathematical modeling] spanning tree based on Matlab GUI random nodes [including Matlab source code 1919]
VB. Net class library (Advanced - 2 overload)
Operations research says that in issue 66, Behrman also has "speech phobia"?
Unity cloth system_ Cloth component (including dynamic call related)
[mixed programming JNI] Part 6: operation of strings and arrays in native
Microservices, an important part of cloud native architecture
软件工程导论——第四章——形式化说明技术
Unity4.6 Download
Open world mecha games phantom Galaxy
golang语言的开发学习路线
[mixed programming JNI] Part 12 jnaerator