当前位置:网站首页>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;
}
}边栏推荐
猜你喜欢

MySQL table common operation mind map

商城开发知识点

Fatal error in launcher: unable to create process using

Google Ads 竞价的运作机制

MySQL advanced knowledge points

程序员应该如何解决买菜难问题?手把手带你利用无障碍辅助功能快速下单抢菜
![[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

自适应搜索广告有哪些优势?

Various error reporting solutions encountered by Kali during Empire installation

阿里云oss文件上传系统
随机推荐
Niuke monthly race 14- simple counting
Force deduction solution summary 1728- cat and mouse II
力扣解法汇总433-最小基因变化
高考完不要急着去打工了,打工以后有的是机会,不差这三个月
2022最全面的Redis事务控制(带图讲解)
Leetcode 45 jump game II
Linux (centos7) installer mysql - 5.7
力扣解法汇总462-最少移动次数使数组元素相等 II
力扣解法汇总-04.06. 后继者
Pagination writing of PHP security open 10 article list module
What insurance products can you buy at the age of 60?
A mystery of the end of vagrant up
Google Ads 竞价的运作机制
入手Ticwatch2
C language programming classic games - minesweeping
How WPS inserts a directory and the operating steps for quickly inserting a directory
力扣解法汇总824-山羊拉丁文
PHP security development 13 column module of blog system
为什么我们要使用谷歌搜索广告?
Modification of system module information of PHP security development 12 blog system