当前位置:网站首页>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;
}
边栏推荐
- On cap theorem in distributed system development technology
- Do an online GIF synthesis service at no cost
- Color matching and related issues
- C language: a simple calculator is implemented by using code many times
- 【混合编程jni 】第九篇之Jni总结
- Leetcode - the best time to buy or sell stocks
- 數據清洗工具flashtext,效率直接提昇了幾十倍數
- Unityeditor Editor Extension - table function
- Microservices, an important part of cloud native architecture
- 想买股票请问在券商公司的哪里开户佣金低更安全
猜你喜欢
300题 第三讲 向量组
Unity4.6版本下载
Simple test lightweight expression calculator fly
UnityEditor編輯器擴展-錶格功能
Microservices, an important part of cloud native architecture
CVPR2022-不对称分辨率图像的立体匹配
开放世界机甲游戏-Phantom Galaxies
Bs-gx-016 implementation of textbook management system based on SSM
软件工程导论——第四章——形式化说明技术
Unity4.6 Download
随机推荐
想买股票请问在券商公司的哪里开户佣金低更安全
[kotlin] keyword suspend learning of thread operation and async understanding
如何写好测试用例以及go单元测试工具testify简单介绍
Implement the queue through two stacks
300 questions lesson 3 vector group
【界面】pyqt5和Swin Transformer对人脸进行识别
Are there any risks for the top ten securities companies to register and open accounts? Is it safe?
Leetcode (763) -- dividing letter ranges
Is it safe to open an account and buy stocks? Who knows
Tensorrt笔记(七)Tensorrt使用问题整理
Partage de trois méthodes de sommation automatique dans un tableau Excel
【Try to Hack】正向shell和反向shell
Raspberry pie preliminary use
Smartbi gives you a piece to play with Boston matrix
Would you like to buy stocks? Where do you open an account in a securities company? The Commission is lower and safer
您的连接不是私密连接
Openpyxl module
Selenium电脑上怎么下载-Selenium下载和安装图文教程[超详细]
6.24 learning content
不花一分钱做个在线的gif合成服务