[LeetCode] Kth Smallest Number in Multiplication Table 乘法表中的第K小的数字

Nearly every one have used the Multiplication Table. But could you find out the k-th smallest number quickly from the multiplication table?

Given the height m and the length n of a m * n Multiplication Table, and a positive integer k, you need to return the k-th smallest number in this table.

Example 1:

Input: m = 3, n = 3, k = 5
Output:
Explanation:
The Multiplication Table:
1	2	3
2	4	6
3	6	9

The 5-th smallest number is 3 (1, 2, 2, 3, 3).

Example 2:

Input: m = 2, n = 3, k = 6
Output:
Explanation:
The Multiplication Table:
1	2	3
2	4	6

The 6-th smallest number is 6 (1, 2, 2, 3, 4, 6).

Note:

  1. The m and n will be in the range [1, 30000].
  2. The k will be in the range [1, m * n]

s

原文地址:https://www.cnblogs.com/grandyang/p/8367505.html

时间: 2024-08-29 17:30:37

[LeetCode] Kth Smallest Number in Multiplication Table 乘法表中的第K小的数字的相关文章

LeetCode:乘法表中的第K小的数【668】

LeetCode:乘法表中的第K小的数[668] 题目描述 几乎每一个人都用 乘法表.但是你能在乘法表中快速找到第k小的数字吗? 给定高度m .宽度n 的一张 m * n的乘法表,以及正整数k,你需要返回表中第k 小的数字. 例 1: 输入: m = 3, n = 3, k = 5 输出: 3 解释: 乘法表: 1 2 3 2 4 6 3 6 9 第5小的数字是 3 (1, 2, 2, 3, 3). 例 2: 输入: m = 2, n = 3, k = 6 输出: 6 解释: 乘法表: 1 2

668. Kth Smallest Number in Multiplication Table

Nearly every one have used the Multiplication Table. But could you find out the k-th smallest number quickly from the multiplication table? Given the height m and the length n of a m * n Multiplication Table, and a positive integer k, you need to ret

[Leetcode]668.Kth Smallest Number in Multiplication Table

链接:LeetCode668 给定高度m?.宽度n 的一张?m * n的乘法表,以及正整数k,你需要返回表中第k?小的数字. 例?1: 输入: m = 3, n = 3, k = 5 输出: 3 解释: 乘法表: 1 2 3 2 4 6 3 6 9 第5小的数字是 3 (1, 2, 2, 3, 3). 相关标签:二分查找 乘法表的特点是每行和每列元素均按升序排序,这题就可以转换为[LeetCode]378.Kth Smallest Element in a Sorted Matrix.我们通过二

230 Kth Smallest Element in a BST 二叉搜索树中第K小的元素

给定一个二叉搜索树,编写一个函数kthSmallest来查找其中第k个最小的元素. 注意:你可以假设k总是有效的,1≤ k ≤二叉搜索树元素个数. 进阶:如果经常修改二叉搜索树(插入/删除操作)并且你需要频繁地找到第k小值呢? 你将如何优化kthSmallest函数? 详见:https://leetcode.com/problems/kth-smallest-element-in-a-bst/description/ 方法一:递归实现 /** * Definition for a binary

[Lintcode] Kth Smallest Number in Sorted Matrix

Kth Smallest Number in Sorted Matrix Find the kth smallest number in at row and column sorted matrix. Have you met this question in a real interview? Yes Example Given k = 4 and a matrix: [ [1 ,5 ,7], [3 ,7 ,8], [4 ,8 ,9], ] return 5 Challenge O(k lo

Kth Smallest Number in Sorted Matrix

Find the kth smallest number in at row and column sorted matrix. Example Given k = 4 and a matrix: [ [1 ,5 ,7], [3 ,7 ,8], [4 ,8 ,9], ] return 5. 分析: Although the matrix is horizontally and vertically sorted, there is no rule to find the next smalles

[LeetCode] K-th Smallest in Lexicographical Order 字典顺序的第K小数字

Given integers n and k, find the lexicographically k-th smallest integer in the range from 1 to n. Note: 1 ≤ k ≤ n ≤ 109. Example: Input: n: 13 k: 2 Output: 10 Explanation: The lexicographical order is [1, 10, 11, 12, 13, 2, 3, 4, 5, 6, 7, 8, 9], so

Leetcode: K-th Smallest in Lexicographical Order

Given integers n and k, find the lexicographically k-th smallest integer in the range from 1 to n. Note: 1 ≤ k ≤ n ≤ 109. Example: Input: n: 13 k: 2 Output: 10 Explanation: The lexicographical order is [1, 10, 11, 12, 13, 2, 3, 4, 5, 6, 7, 8, 9], so

[LeetCode] Kth Smallest Element in a Sorted Matrix 有序矩阵中第K小的元素

Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix. Note that it is the kth smallest element in the sorted order, not the kth distinct element. Example: matrix = [ [ 1, 5