JavaScript-Simple Baidu School recruit questions, see a variety of solutions?

Source: Internet
Author: User
Keywords javascript c++ c java php

Reply content:

I have not done this problem, the provisional thought of the algorithm:

Two points to the target, assuming that the current number is num , then traverse each row, for the first i row, no greater than num the number of numbers is min(num / i, m) , accumulated after the total count cnt .

If cnt less than k then to the right half of the range continue to find, otherwise to the left half to continue to find.

Time complexity, more than O(n * log(n * m)) sufficient.

Direct use of subscript query, each row is a multiple of the first row

It can be found that the multiplication table results in the size of the diagonal line, so follow this method to find the law.

N*m Matrix results you need it.
I'll give you a way to build a 0-n*m array A, each element is 0,
Then you have two for loops to calculate each number of T in the Matrix, will a[t]++,
After the calculation you have a one-dimensional array that might be "0,1,2,3,1,0,2,5, ... 】
You add from left to right until the result is greater than or equal to K, and the subscript i is the result you want

def multiply(n, m, k):    if k > n * m:        return None    l = []    for i in range(1, n + 1):        for j in range(1, m + 1):            l.append(i * j)    return l[k]print multiply(2,3, 7)
  • 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.