当前位置:网站首页>Nc29 search in two-dimensional array
Nc29 search in two-dimensional array
2022-07-06 09:40:00 【I'm not Xiao Haiwa~~~~】
describe
In a two-dimensional array array in ( Each one-dimensional array has the same length ), Each row is sorted in ascending order from left to right , Each column is sorted in ascending order from top to bottom . Please complete a function , Enter such a two-dimensional array and an integer , Determine whether the array contains the integer .
[
[1,2,8,9],
[2,4,9,12],
[4,7,10,13],
[6,8,11,15]
]
Given target = 7, return true.
Given target = 3, return false.
Advanced : Spatial complexity O(1)O(1) , Time complexity O(n+m)O(n+m)
Example 1
Input :
7,[[1,2,8,9],[2,4,9,12],[4,7,10,13],[6,8,11,15]]
Return value :
true
explain :
There is 7, return true
Example 2
Input :
1,[[2]]
Return value :
false
Example 3
Input :
3,[[1,2,8,9],[2,4,9,12],[4,7,10,13],[6,8,11,15]]
Return value :
false
explain :
non-existent 3, return false
Code:
class Solution {
public:
bool Find(int target, vector<vector<int> > array) {
for(int i=0;i<array.size();i++)
{
vector<int> subvec=array[i];
for(int j=0;j<subvec.size();j++)
{
vector<int>::iterator it=find(subvec.begin(),subvec.end(),target);
if(it!=subvec.end())
return true;
}
}
return false;
}
};
边栏推荐
- Vs All comments and uncomments
- Global and Chinese market of metallized flexible packaging 2022-2028: Research Report on technology, participants, trends, market size and share
- Redis之哨兵模式
- Redis之哨兵模式
- Global and Chinese markets for small seed seeders 2022-2028: Research Report on technology, participants, trends, market size and share
- May brush question 02 - string
- MapReduce instance (V): secondary sorting
- Solve the problem of inconsistency between database field name and entity class attribute name (resultmap result set mapping)
- June brush question 02 - string
- The five basic data structures of redis are in-depth and application scenarios
猜你喜欢
随机推荐
Interview shock 62: what are the precautions for group by?
Webrtc blog reference:
面渣逆袭:Redis连环五十二问,图文详解,这下面试稳了
英雄联盟轮播图手动轮播
QML type: locale, date
五月刷题03——排序
Global and Chinese markets of SERS substrates 2022-2028: Research Report on technology, participants, trends, market size and share
Basic concepts of libuv
Global and Chinese market of airport kiosks 2022-2028: Research Report on technology, participants, trends, market size and share
Scoped in webrtc_ refptr
Redis之主从复制
Redis之cluster集群
June brush question 01 - array
【深度学习】语义分割:论文阅读:(CVPR 2022) MPViT(CNN+Transformer):用于密集预测的多路径视觉Transformer
Global and Chinese market of cup masks 2022-2028: Research Report on technology, participants, trends, market size and share
《ASP.NET Core 6框架揭秘》样章发布[200页/5章]
Kratos战神微服务框架(三)
Kratos ares microservice framework (III)
MapReduce working mechanism
[Yu Yue education] reference materials of complex variable function and integral transformation of Shenyang University of Technology