Skip to content

Commit 9863a46

Browse files
committed
Runtime: 27 ms (Top 26.50%) | Memory: 6 MB (Top 28.37%)
1 parent 38fce5a commit 9863a46

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

scripts/algorithms/K/Kth Smallest Number in Multiplication Table/Kth Smallest Number in Multiplication Table.cpp

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
1+
// Runtime: 27 ms (Top 26.50%) | Memory: 6 MB (Top 28.37%)
12
class Solution {
23
public:
3-
4+
45
int findKthNumber(int m, int n, int k) {
56
int high=m*n ,low=1;
6-
7+
78
int mid=0, ans=1e9;
89
while(low<=high)
910
{
1011
mid=low+(high-low)/2;
1112
int temp=0;
12-
13-
// for each i find the max value ,less than or equal to n , such that
14-
// i*j<=mid
15-
// add j to answer
13+
14+
// for each i find the max value ,less than or equal to n , such that
15+
// i*j<=mid
16+
// add j to answer
1617
for(int i=1;i<=m;i++)
1718
temp+=min(mid/i,n);
18-
19+
1920
if(temp>=k)
2021
{
2122
ans=min(ans,mid);
2223
high=mid-1;
2324
}
2425
else
2526
low=mid+1;
26-
27+
2728
}
2829
return ans;
2930
}

0 commit comments

Comments
 (0)