当前位置:网站首页>Leetcode 718. Longest repeating subarray (violence enumeration, to be solved)
Leetcode 718. Longest repeating subarray (violence enumeration, to be solved)
2022-06-26 23:22:00 【I'm not xiaohaiwa~~~~】
Give two arrays of integers nums1 and nums2 , return In two arrays Public 、 The length of the longest subarray .
Example 1:
Input :nums1 = [1,2,3,2,1], nums2 = [3,2,1,4,7]
Output :3
explain : The longest common subarray is [3,2,1] .
Example 2:
Input :nums1 = [0,0,0,0,0], nums2 = [0,0,0,0,0]
Output :5
Tips :
- 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;
}
边栏推荐
- go语言中的私聊功能处理
- Wechat applet automatically generates punch in Poster
- VB. Net class library to obtain the color under the mouse in the screen (Advanced - 3)
- 炒股手机上开户可靠吗? 网上开户炒股安全吗
- 在手机开户买股票安全吗 网上开户炒股安全吗
- go语言的服务发现、存储引擎、静态网站
- Microservices and container choreography in go
- Unity3d plug-in anyportrait 2D bone animation
- 有哪些劵商推荐?现在在线开户安全么?
- 电子协会 C语言 1级 29 、 对齐输出
猜你喜欢

固有色和环境色

Open world mecha games phantom Galaxy

Crawler and Middleware of go language

阿里云服务器的购买、基本配置、(xshell)远程连接、搭建环境

A simple and crude method for exporting R language list to local

Extensions de l'éditeur d'unityeditor - fonctions de table

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

L'outil de nettoyage des données flashtext améliore directement l'efficacité de plusieurs dizaines de fois

數據清洗工具flashtext,效率直接提昇了幾十倍數

BS-GX-016基于SSM实现教材管理系统
随机推荐
Simple test lightweight expression calculator fly
Solid and ambient colors
ASP.Net Core创建MVC项目上传文件(缓冲方式)
Système de distribution Unity Composants en tissu (y compris les dépendances d'appel dynamique)
What are the test case design methods?
【老卫搞机】090期:键盘?主机?全功能键盘主机!
C语言:简单计算器多次使用代码实现
Flashtext, a data cleaning tool, has directly increased the efficiency by dozens of times
A simple and crude method for exporting R language list to local
为什么我不推荐去SAP培训机构参加培训?
Leetcode 718. 最长重复子数组(暴力枚举,待解决)
股票开户有哪些优惠活动?手机开户安全么?
Leetcode - the best time to buy or sell stocks
Is it safe to open an account and speculate in stocks on the mobile phone? Is it safe to open an account and speculate in stocks on the Internet
Unity: the referenced script (unknown) on this behavior is missing“
[interface] pyqt5 and swing transformer for face recognition
Unity布料系统_Cloth组件(包含动态调用相关)
[machine learning] - Introduction to vernacular and explanation of terms
[kotlin] keyword suspend learning of thread operation and async understanding
CVPR2022-不对称分辨率图像的立体匹配