1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| class Solution { public: bool Find(int target, vector<vector<int> > array) { bool isExist = false; int lenghtY = array.size(); for (int i = 0; i < array[0].size();) { if (lenghtY - 1 < 0 || i > array[0].size()) { return false; } if (target > array[lenghtY - 1][i]) { i++; } else if (target < array[lenghtY - 1][i]) { lenghtY--; } else if (target == array[lenghtY - 1][i]) { isExist = true; break; } } return isExist; } };
|