力扣668.乘法表中第k小的数

力扣668.乘法表中第k小的数

  • 二分查找

    • 是否有k个比mid小的数
cpp 复制代码
  class Solution {
  public:
      int findKthNumber(int m, int n, int k) {
          auto check = [&](int mid) -> bool
          {
              int res=0;
              int row = 1,col = n;
              while(row <= m)
              {
                  if(row * col <= mid)
                  {
                      res += col;
                      if(res >= k) return false;
                      row ++;
                  }
                  else col --;
              }
              return true;
          };
          int l = 1,r = n * m;
          while(l<r)
          {
              int mid = l + r + 1 >> 1;
              if(check(mid)) l = mid;
              else r = mid - 1;
          }
          return r + 1;
      }
  };
相关推荐
策案案案35 分钟前
YOLO: 将AI Agents嵌入到IntelliJ IDEA
java·大数据·人工智能·笔记·yolo·microsoft·intellij-idea
a187927218311 小时前
【算法】动态规划第四篇:背包收官——min 哨兵、计数世界与组合排列分水岭
算法·leetcode·动态规划·dp·01背包·算法讲解·决策合并
2601_962297481 小时前
在python3中、下列输出变量a的正确写法是_2020超星大数据Python免费答案
数据结构·python·算法·编程·字符串操作
辰烨chenye2 小时前
LeetCode Hot 100 题解 · 子串篇
算法·leetcode·职场和发展
辰烨chenye2 小时前
LeetCode Hot 100 题解 · 堆篇
java·算法·leetcode
手写码匠2 小时前
华为云Flexus+DeepSeek征文|DeepSeek 应用监控告警体系实战:从“用户投诉才知道“到“故障前就发现“
人工智能·深度学习·算法·aigc
shehuiyuelaiyuehao3 小时前
算法29,前缀和,除自身以外的数组的乘积
java·数据结构·算法
智购科技自动售货机厂家3 小时前
2026自动售货机设备清洁效果自动验证:从图像比对到评分算法的工程实践~YH
人工智能·算法·计算机视觉
小刘在重生~3 小时前
Java常用类|String类详解 + BigDecimal精准计算(含面试题)
java·开发语言·python
随遇而安zx3 小时前
【多线程】---JMM 与 volatile 深度解析
java·多线程