当前位置:网站首页>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;
}
}边栏推荐
- xcall 集群脚本(查看jps命令)
- The establishment and introduction of the announcement module of PHP development blog system
- UE4\UE5触摸屏touch事件:单指、双指
- 程序员应该如何解决买菜难问题?手把手带你利用无障碍辅助功能快速下单抢菜
- 力扣解法汇总面试题 17.11-单词距离
- php开发 博客系统的公告模块的建立和引入
- How to automatically color cells in Excel
- MySQL高级部分知识点
- "China Dongxin Cup" the fourth programming competition of Guangxi University (synchronous competition)
- Linux (centos7) installer mysql - 5.7
猜你喜欢

MySQL advanced knowledge points

BaseDexClassLoader那些事

Ozzanation - système d'action basé sur sse

Installing MySQL version 5.5 database for Linux (centos6)

How WPS inserts a directory and the operating steps for quickly inserting a directory

Basedexclassloader

MySQL表常用操作思维导图

程序员应该如何解决买菜难问题?手把手带你利用无障碍辅助功能快速下单抢菜

Alicloud OSS file upload system

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
随机推荐
Linux(CentOS6)安装MySQL5.5版本数据库
ozzanimation-基于sse的动作系统
自适应搜索广告有哪些优势?
微信公众号开发地理位置坐标的转换
Summary of force deduction method 417- Pacific Atlantic current problems
php安全开放10文章列表模块的分页编写
如何定位关键词使得广告精准投放。
代理与反射(二)
Modification of system module information of PHP security development 12 blog system
PHP development 09 article module deletion and article classification writing
Summary of concrete (ground + wall) + Mountain crack data set (classification and target detection)
A mystery of the end of vagrant up
Ozzanmation action system based on SSE
Graphic data analysis | data cleaning and pretreatment
ACL 2022 | 预训练语言模型和图文模型的强强联合
How to locate keywords to make advertising accurate.
MySQL table common operation mind map
Various error reporting solutions encountered by Kali during Empire installation
力扣解法汇总883-三维形体投影面积
Installing MySQL version 5.5 database for Linux (centos6)