Search a 2D Matrix

Search a 2D Matrix

You are given an m x n integer matrix matrix with the following two properties:

  • Each row is sorted in non-decreasing order.
  • The first integer of each row is greater than the last integer of the previous row.

Given an integer target, return true if target is in matrix or false otherwise.

You must write a solution in O(log(m * n)) time complexity.

Example 1:

Input: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3

Output: true

Example 2:

Input: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13

Output: false

?

Constraints:

  • m == matrix.length
  • n == matrix[i].length
  • 1 <= m,n <= 100
  • -10? <= matrix[i][j], target <= 10?

SOLUTION:




要查看或添加评论,请登录

Bekir Sahin的更多文章

  • Mastering Prompt Engineering: A Comprehensive Framework

    Mastering Prompt Engineering: A Comprehensive Framework

    In the rapidly evolving fields of artificial intelligence and data science, clear and precise instructions are vital…

    1 条评论
  • Simplify Path

    Simplify Path

    Given an absolute path for a Unix-style file system, which begins with a slash '/', transform this path into its…

  • Combinations

    Combinations

    Given two integers n and k, return all possible combinations of k numbers chosen from the range [1, n]. You may return…

  • Add Binary

    Add Binary

    Given two binary strings a and b, return their sum as a binary string. Example 1: Input: a = 11, b = 1 Output: 100…

  • Summary Ranges

    Summary Ranges

    You are given a sorted unique integer array nums. A range [a,b] is the set of all integers from a to b (inclusive).

  • Longest Substring Without Repeating Characters

    Longest Substring Without Repeating Characters

    Given a string s, find the length of the longest substring without repeating characters. Example 1: Input: s =…

  • Integer to Roman

    Integer to Roman

    Seven different symbols represent Roman numerals with the following values: Symbol Value I 1 V 5 X 10 L 50 C 100 D 500…

  • Minimum Size Subarray Sum

    Minimum Size Subarray Sum

    Given an array of positive integers nums and a positive integer target, return the minimal length of a subarray whose…

  • Reverse Words in a String

    Reverse Words in a String

    Given an input string s, reverse the order of the words. A word is defined as a sequence of non-space characters.

  • Rotate Array

    Rotate Array

    Given an integer array nums, rotate the array to the right by k steps, where k is non-negative. Example 1: Input: nums…

社区洞察

其他会员也浏览了