problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::k_th_smallest_in_lexicographical_order::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static int findKthNumber (int n, int k)
 
static int getSteps (int curr, long n)
 

详细描述

在文件 leetcode.h1893 行定义.

成员函数说明

◆ findKthNumber()

int leetcode::k_th_smallest_in_lexicographical_order::Solution::findKthNumber ( int  n,
int  k 
)
static

在文件 leetcode.cpp4955 行定义.

4955 {
4956 int curr = 1;
4957 k--;
4958 while(k > 0) {
4959 const int steps = getSteps(curr, n);
4960 if(steps <= k) {
4961 k -= steps;
4962 curr++;
4963 } else {
4964 curr = curr * 10;
4965 k--;
4966 }
4967 }
4968 return curr;
4969 }

引用了 getSteps().

被这些函数引用 leetcode::k_th_smallest_in_lexicographical_order::TEST().

◆ getSteps()

int leetcode::k_th_smallest_in_lexicographical_order::Solution::getSteps ( int  curr,
long  n 
)
static

在文件 leetcode.cpp4971 行定义.

4971 {
4972 int steps = 0;
4973 long first = curr;
4974 long last = curr;
4975 while(first <= n) {
4976 steps += min(last, n) - first + 1;
4977 first = first * 10;
4978 last = last * 10 + 9;
4979 }
4980 return steps;
4981 }

被这些函数引用 findKthNumber().


该类的文档由以下文件生成: