当前位置:网站首页>Force deduction solution summary 668- the smallest number k in the multiplication table
Force deduction solution summary 668- the smallest number k in the multiplication table
2022-06-12 02:08:00 【Lost summer】
Directory links :
Force buckle programming problem - The solution sums up _ Share + Record -CSDN Blog
GitHub Synchronous question brushing items :
https://github.com/September26/java-algorithms
Original link : Power button
describe :
Almost everyone uses Multiplication table . But you can quickly find the number... In the multiplication table k Small number ?
Given height m 、 Width n One of the m * n The multiplication table of , And positive integers k, You need to go back to... In the table k Small numbers .
example 1:
Input : m = 3, n = 3, k = 5
Output : 3
explain :
Multiplication table :
1 2 3
2 4 6
3 6 9
The first 5 The small number is 3 (1, 2, 2, 3, 3).
example 2:
Input : m = 2, n = 3, k = 6
Output : 6
explain :
Multiplication table :
1 2 3
2 4 6
The first 6 The small number is 6 (1, 2, 2, 3, 4, 6).
Be careful :
m and n The scope of [1, 30000] Between .
k The scope of [1, m * n] Between .
source : Power button (LeetCode)
link :https://leetcode.cn/problems/kth-smallest-number-in-multiplication-table
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
Their thinking :
* Their thinking : * I didn't come up with an answer to the question , Finally, I figured it out by looking at the solution of the problem . * I still have a doubt , Each dichotomy search is better than middle How many times are there small numbers , How to guarantee the last one middle+1 perhaps right It must be the number in the multiplication table ?
Code :
public class Solution668 {
public int findKthNumber(int m, int n, int k) {
int left = 1;
int right = m * n;
int middle = 0;
while (left < right) {
middle = left + (right - left) / 2;
// Seek less than middle The number of
int count = 0;
for (int i = 1; i <= m; i++) {
int min = Math.min(m, middle / i);
count += min;
}
if (count >= k) {
right = middle;
continue;
}
left = middle + 1;
}
return left;
}
}边栏推荐
- 力扣解法汇总868-二进制间距
- How should programmers solve the problem of buying vegetables? Take you hand in hand to quickly order and grab vegetables by using the barrier free auxiliary function
- Design principle [Demeter's Law]
- PHP development 09 article module deletion and article classification writing
- php安全开发 12博客系统的 系统模块信息的修改
- 阿里云oss文件上传系统
- Summary of force deduction method 417- Pacific Atlantic current problems
- 力扣解法汇总433-最小基因变化
- Wide match modifier symbol has been deprecated, do not use
- Almost all schools will ask for the second round exam! Come in and recite the answer!
猜你喜欢

Graphic data analysis | business cognition and data exploration

php开发 博客系统的公告模块的建立和引入

C language programming classic games - minesweeping

Google Ads 竞价的运作机制

What are the advantages of adaptive search advertising?

为什么我们要使用谷歌搜索广告?
![[adjustment] in 2022, the Key Laboratory of laser life sciences of the Ministry of education of South China Normal University enrolled adjustment students in optics, electronic information, biomedicin](/img/f9/332b206d5aca0ca6afc3fdf11a53c8.jpg)
[adjustment] in 2022, the Key Laboratory of laser life sciences of the Ministry of education of South China Normal University enrolled adjustment students in optics, electronic information, biomedicin

MySQL table common operation mind map

MySQL advanced knowledge points

Oracle 11g graphic download installation tutorial (step by step)
随机推荐
How to improve the advertising rating of advertising, that is, the quality score?
[adjustment] in 2022, the Key Laboratory of laser life sciences of the Ministry of education of South China Normal University enrolled adjustment students in optics, electronic information, biomedicin
Swiftyjson analyse les fichiers json locaux
力扣解法汇总面试题 17.11-单词距离
力扣解法汇总473-火柴拼正方形
SQL calculates KS, AUC, IV, psi and other risk control model indicators
Summary of force deduction method 417- Pacific Atlantic current problems
Graphic data analysis | data cleaning and pretreatment
力扣解法汇总388-文件的最长绝对路径
Fatal error in launcher: unable to create process using
ozzanimation-基于sse的动作系统
通用树形结构的迭代与组合模式实现方案
决定广告质量的三个主要因素
The force deduction solution summarizes the shortest distance of 821 characters
DDD的分层架构
Knowledge points of mall development
Design principle [Demeter's Law]
"China Dongxin Cup" the fourth programming competition of Guangxi University (synchronous competition)
力扣解法汇总668-乘法表中第k小的数
Force deduction solution summary 386 dictionary order