标签:code size 移动 维数 vector question 题目 -- span
1 class Solution { 2 public: 3 bool Find(int target, vector<vector<int>> array) { 4 int px = array.size(), py = array[0].size(); 5 if (px==0 || py == 0 ||target<array[0][0] || target>array[px - 1][py - 1])return false; 6 for (int x = 0, y = 0; y < py && x < px &&y >= 0 && x>=0;) 7 { 8 if (target == array[x][y])return true; 9 else if ((y == py-1 && target > array[x][y])||(y < py - 1 && target < array[x][y + 1] && target > array[x][y])) 10 ++x; 11 else if (target < array[x][y]) 12 --y; 13 else 14 y++; 15 } 16 return false; 17 } 18 };
1 class Solution { 2 public: 3 bool Find(int target, vector<vector<int>> array) { 4 int px = array.size(), py = array[0].size(); 5 if (target<array[0][0] || target>array[px - 1][py - 1])return false; 6 int x = 0, y = py - 1; 7 while (x < px && y >= 0) 8 { 9 if (target == array[x][y])return true; 10 else if (target > array[x][y]) ++x; 11 else if (target < array[x][y]) --y; 12 } 13 return false; 14 } 15 };
标签:code size 移动 维数 vector question 题目 -- span
原文地址:https://www.cnblogs.com/zzw1024/p/11649975.html