cswork / OA打开练习工作台

AccentureOA #1

Smallest Number Greater Than K

估计中等评测数据准备中,可先阅读题面

考点(AI 标注)回溯枚举字符串

You are given an integer n and a threshold integer k. Your task is to form the smallest number possible from the digits of n by deleting some digits, while maintaining the original order of the digits. The formed number must be greater than k. Details: You must preserve the order of the digits from n. If the smallest number you can form is less than or equal to k, try to include additional digits from n to ensure the result is greater than k. Function Signature: string smallestNumberGreaterThanK(string numStr, int k);

Example 1

Input:

numStr = "7195"
k = 16

Output:

"19"

Explanation: For n = 7195 and k = 16, the output should be 19.

Example 2

Input:

numStr = "7195"
k = 14

Output:

"15"

Explanation: For n = 7195 and k = 14, the output should be 15.