Baidu PHP Internship one side of the test-algorithm-two-dimensional ordered matrix lookup

Source: Internet
Author: User
Title Description

There is a two-dimensional matrix, each row of elements, left to right to maintain a strict increment, the elements of each column, from top to bottom to maintain a strict increment. Finds the given element Elem, returning null or element position.

1 3 7 15 16
2 5 8 17 19
3 6 9 18 20
7 18 20 22 24
9 23 24 28 33
Thinking first from the diagonal, the upper left is the minimum matrix, the lower right corner is the maximum value, not within the interval, the value of the lookup is not within the matrix, otherwise: from the lower left corner, if the current element is greater than elem, then go up; Complexity O (m+n).

Baidu PHP Internship one side of the test-algorithm-two-dimensional ordered matrix lookup

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.