【leetcode】668. Kth Smallest Number in Multiplication Table
题目如下:

解题思路:几乎和【leetcode】719. Find K-th Smallest Pair Distance 的方法一样。只不过一个是减法一个是乘法,还有一点区别是【leetcode】719. Find K-th Smallest Pair Distance中i-j和j-i只算一个元素,而本题中i*j与j*i算两个元素。
代码如下:
class Solution(object):
def findKthNumber(self, m, n, k):
"""
:type m: int
:type n: int
:type k: int
:rtype: int
"""
low,high = 1, m*n while low <= high:
mid = (low + high) / 2
less,equal = 0,0
for i in range(1,min(mid+1,m+1)):
less += min(mid/i,n)
if mid/i <= n and mid % i == 0:
equal += 1
less -= 1 if less >= k:
high = mid - 1
elif less + equal < k:
low = mid + 1
elif less == k and equal == 0:
high = mid - 1
else:
break
return mid
【leetcode】668. Kth Smallest Number in Multiplication Table的更多相关文章
- LeetCode hard 668. Kth Smallest Number in Multiplication Table(二分答案,一次过了,好开心,哈哈哈哈)
题目:https://leetcode.com/problems/kth-smallest-number-in-multiplication-table/description/ 668. Kth S ...
- 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 ...
- 【LeetCode】378. Kth Smallest Element in a Sorted Matrix 解题报告(Python)
[LeetCode]378. Kth Smallest Element in a Sorted Matrix 解题报告(Python) 标签: LeetCode 题目地址:https://leetco ...
- [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 ...
- [Swift]LeetCode668. 乘法表中第k小的数 | Kth Smallest Number in Multiplication Table
Nearly every one have used the Multiplication Table. But could you find out the k-th smallest number ...
- 【LeetCode】230. Kth Smallest Element in a BST
Difficulty: Medium More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/kth-smallest- ...
- 【leetcode】378. Kth Smallest Element in a Sorted Matrix(TOP k 问题)
Given an n x n matrix where each of the rows and columns is sorted in ascending order, return the kt ...
- 【Leetcode】378. Kth Smallest Element in a Sorted Matrix
Question: Given a n x n matrix where each of the rows and columns are sorted in ascending order, fin ...
- 【LeetCode】230. Kth Smallest Element in a BST (2 solutions)
Kth Smallest Element in a BST Given a binary search tree, write a function kthSmallest to find the k ...
随机推荐
- IPv6测试环境搭建
IPv6的简介 IPv4 和 IPv6的区别就是 IP 地址前者是 .(dot)分割,后者是以 :(冒号)分割的(更多详细信息自行搜索). PS:在使用 IPv6 的热点时候,记得手机开 飞行模式 哦 ...
- 让dcef3支持mp3和h.264 mp4解码播放
嵌入式Chromium框架(简称CEF) 是一个由Marshall Greenblatt在2008建立的开源项目,它主要目的是开发一个基于Google Chromium的Webbrowser控件.CE ...
- Win7 64位注册32位DLL
记忆力越来越差,备忘. 参考地址 https://support.microsoft.com/en-us/help/249873/how-to-use-the-regsvr32-tool-and-tr ...
- Eclipse + pydev插件
在Eclipse中安装pydev插件 启动Eclipse, 点击Help->Install New Software... 在弹出的对话框中,点Add 按钮. Name中填:Pydev, ...
- CSS的置换和非置换元素
一个来自面试的坑. 面试的时候考官先问了行内元素和块级元素的区别,这个不难理解.然后一脚就踩进了,置换元素的坑.例如img就是行内置换元素,这种行内元素是可以设置宽高的. 什么是置换元素 一个内容不受 ...
- [Bzoj1003][ZJOI2006]物流运输(spfa+dp)
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1003 比较简单的dp,dp[i]为1-i天最小费用,dp方程为dp[i] = min(d ...
- [fw]拦截系统调用
今天在ubuntu中玩了下“拦截系统调用”,记录下自己对整个实现的理解. 原理 在linux kernel中,系统调用都放在一个叫做“sys_call_table”的分配表里面,在进入一个系统调用的最 ...
- 【经典转载】关于Struts2的拦截器
拦截器(interceptor)是Struts2最强大的特性之一,也可以说是struts2的核心,拦截器可以让你在Action和result被执行之前或之后进行一些处理.同时,拦截器也可以让你将通用的 ...
- 70.Trapping Rain Water(容水量)
Level: Hard 题目描述: Given n non-negative integers representing an elevation map where the width of e ...
- rmdir -删除空目录
总览 rmdir[options]directory... POSIX 选项: [-p] GNU 选项(缩写): [-p] [--ignore-fail-on-non-empty] [--help] ...