leetcode之Search a 2D Matrix
来源:互联网 发布:各种破解软件 编辑:程序博客网 时间:2024/05/05 14:15
class Solution {
public:
bool searchMatrix(vector<vector<int> > &matrix, int target) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int m = matrix.size();
int n = matrix[0].size();
/*for (int i=m-1; i>=0; i--) {
for (int j=n-1; j>=0; j--) {
if (matrix[i][j] > target) {
i--;
}
}
}*/
int i=0, j=n-1;
while(i<m && j>=0) {
if (target>matrix[i][j]) {
i++;
} else if (target< matrix[i][j]) {
j--;
} else {
return true;
}
}
return false;
}
};
public:
bool searchMatrix(vector<vector<int> > &matrix, int target) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int m = matrix.size();
int n = matrix[0].size();
/*for (int i=m-1; i>=0; i--) {
for (int j=n-1; j>=0; j--) {
if (matrix[i][j] > target) {
i--;
}
}
}*/
int i=0, j=n-1;
while(i<m && j>=0) {
if (target>matrix[i][j]) {
i++;
} else if (target< matrix[i][j]) {
j--;
} else {
return true;
}
}
return false;
}
};
- leetcode之Search a 2D Matrix
- LeetCode之Search a 2D Matrix
- LeetCode之Search a 2D Matrix
- leetcode之Search a 2D Matrix
- LeetCode 之 Search a 2D Matrix
- 【Leetcode】之Search a 2D Matrix
- Leetcode 之Search a 2D Matrix
- [leetcode][Search] Search a 2D Matrix
- Leetcode之五Search a 2D Matrix
- LeetCode 之 Search a 2D Matrix — C 实现
- leetcode之Search a 2D Matrix II
- LeetCode 之 Search a 2D Matrix II
- Leetcode之Search a 2D Matrix 问题
- LeetCode: Search a 2D Matrix
- LeetCode Search a 2D Matrix
- [Leetcode] Search a 2D Matrix
- LeetCode : Search a 2D Matrix
- [LeetCode] Search a 2D Matrix
- makefile 常用函数
- 工场outing
- 2013 成都网络赛
- 动机的秘密
- 过好几个
- leetcode之Search a 2D Matrix
- vmware 安装win7
- Windows Server 2012正式版RDS系列⑥
- HDOJ 4731 - Minimum palindrome 找规律
- RCP handler处理函数中获取当前选择项。
- 开始重新复习一下C语言
- FFMPEG中最关键的结构体之间的关系
- 数据读写SD卡下半部分析-mmqcd
- 拆卸 美能达 50 1.7 手动头