Skip to content

Commit 0cf4bfc

Browse files
authored
Create Kth Smallest Number in Multiplication Table.java
1 parent 83d4fa8 commit 0cf4bfc

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public int findKthNumber(int m, int n, int k) {
3+
int low = 0;
4+
int high = m * n;
5+
while (low < high) {
6+
int mid = (low + high) / 2;
7+
int count = 0;
8+
for (int i = 1; i <= m; i++) {
9+
count += Math.min(n, mid / i);
10+
}
11+
if (count >= k) {
12+
high = mid;
13+
} else {
14+
low = mid + 1;
15+
}
16+
}
17+
return low;
18+
}
19+
}

0 commit comments

Comments
 (0)