leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

commit 3402adb00df1ddf844a2efa280220da428d9f944
parent 2231ace554c963cf5592adc6c58a49bd524181c7
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Tue,  7 Feb 2023 15:40:48 +0100

Data Structure II: Day 4

Diffstat:
AProblems/0240.cpp | 14++++++++++++++
MREADME.md | 1+
2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/Problems/0240.cpp b/Problems/0240.cpp @@ -0,0 +1,14 @@ +class Solution { +public: + bool searchMatrix(vector<vector<int>> &matrix, int target) { + int n = matrix.size(), m = matrix[0].size(), x = 0, y = m - 1; + while (x < n && y >= 0) { + if (matrix[x][y] == target) return true; + if (matrix[x][y] > target) + y--; + else + x++; + } + return false; + } +}; diff --git a/README.md b/README.md @@ -157,6 +157,7 @@ for solving problems. | 0237 | Medium | [Delete Node in a Linked List](Problems/0237.cpp) | | 0238 | Medium | [Product of Array Except Self](Problems/0238.cpp) | | 0239 | Hard | [Sliding Window Maximum](Problems/0239.cpp) | +| 0240 | Medium | [Search a 2D Matrix II](Problems/0240.cpp) | | 0242 | Easy | [Valid Anagram](Problems/0242.cpp) | | 0257 | Easy | [Binary Tree Paths](Problems/0257.cpp) | | 0263 | Easy | [Ugly Number](Problems/0263.cpp) |