Search a 2D Matrix

Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:

  • Integers in each row are sorted from left to right.
  • The first integer of each row is greater than the last integer of the previous row.

For example,

Consider the following matrix:

[
  [1,   3,  5,  7],
  [10, 11, 16, 20],
  [23, 30, 34, 50]
]

Given target = 3, return true.

class Solution {
public:
    bool searchMatrix(vector<vector<int> > &matrix, int target) {
        if(target<matrix[0][0])
            return false;
        int row    = matrix.size();
        int column = matrix[0].size();
        if(target>matrix[row-1][column-1])
            return false;
         int i,j;
         
        if(row==1)
     {       for(j=0;j<column;j++)
            {
                if(target==matrix[0][j])
                    return true;
            }
            return false;
    }
       
        for(i=0;i<row;i++)
        {
            if(target<matrix[i][0])
                {
                    for(j=0;j<column;j++)
                    {
                        if(target==matrix[i-1][j])
                            return true;
                    }
                    return false;
                }
        }
         for(j=0;j<column;j++)
             {
                if(target==matrix[row-1][j])
                    return true;
             }
                    return false;
    }
};


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
transform:matrix是CSS3中的一个属性,它用于对元素进行变形操作。matrix()方法是transform属性中的一个函数,它可以通过一个矩阵来实现元素的旋转、缩放、倾斜和平移等变换效果。matrix()方法的参数由六个数字组成,分别代表矩阵的六个值,即a、b、c、d、e和f。通过调整这些值,可以实现不同的变形效果。例如,transform:matrix(1, 0, 0, 1, x, y)表示对元素进行平移操作,其水平偏移量为x,垂直偏移量为y。 通过理解transform中的matrix()矩阵方法,我们可以更深入地理解CSS3中的transform属性,并利用它来实现更丰富多样的元素变形效果。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [CSS3矩阵理解———transform: matrix()改变元素运动的本质](https://blog.csdn.net/weixin_44309019/article/details/88722453)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [HTML 学习笔记 CSS3 (2D Matrix)](https://blog.csdn.net/ddiv24492/article/details/102234967)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值