
本文共 2231 字,大约阅读时间需要 7 分钟。
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
���������������������������������������������������������
���������������������������������������������������������������������0������������false������������������������
���������������������������row������������������������������������rows-1������������������������������������col���������������������������������0������������
���������������������������������������[row][col]������������
- ������������������������������������������������������������������������������������������������(row���1)���������������������������
- ������������������������������������������������������������������������������������������������������������col���1���������������������������
- ���������������������������������������true���������������������������
���������������������������������������������������������false���
���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
������������������������
public class Solution { public boolean Find(int target, int[][] array) { int rows = array.length; if (rows == 0) { return false; } int cols = array[0].length; if (cols == 0) { return false; } int row = rows - 1; int col = 0; while (row >= 0 && col < cols) { if (array[row][col] > target) { row--; } else if (array[row][col] < target) { col++; } else { return true; } } return false; } }
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������O(log(min(rows, cols)))���������������������������������������������������
发表评论
最新留言
关于作者
