⭐ Simple Approach 🚀 🚀 🚀
⭐ Approach
Start at the top-right corner of the matrix: mat[0][n-1]
Use a loop:
★ If the current value == target → return true
★ If current > target → move left

# ⭐ Approach
1. Start at the top-right corner of the matrix: mat[0][n-1]
2. Use a loop:
★ If the current value == target → return true
★ If current > target → move left
★ If current < target → move down
3. If you move out of bounds → target doesn’t exist → return false
This is what your code is doing. Clean and efficient!

# ⭐ Complexity
- ⭐ Time complexity:
★ Worst case: we go all the way down and all the way left
★ So time = O(m + n)

- ⭐ Space complexity:
★No extra space used → O(1)

# Code
```cpp []
class Solution {
public:
    bool searchMatrix(vector<vector<int>>& mat, int target) {
        int m = mat.size(), n = mat[0].size();

        int r = 0, c=n-1;
        while(r < m && c >= 0) {
            if(target == mat[r] [c]) {
                return true;
            } else if (target < mat[r] [c]) {
                c--;
            } else {
                r++;
            }
        }

        return false;
    }
};
```

![cat.png](https://assets.leetcode.com/users/images/ab47c828-47d1-4e01-85d3-6f8e0488c6c9_1744042292.0609412.png)
['C++']