字节经典面试题
给定一个整数n,并从1~9中给定若干个可以使用的数字,根据上述两个条件,得到每一位都为给定可使用数字的、最大的小于整数n的数,例如,给定可以使用的数字为 {2,3,8} 三个数:给定 n=3589,输出3388;给定 n=8234,输出8233;……
#include <iostream>
#include <ostream>
#include <vector>
#include <algorithm>
using namespace std;
//找到小于x的最大值
int find_x(const vector<int>& digits, int x) {
for (auto it = digits.rbegin(); it < digits.rend(); it++) {
if (*it < x) {
return *it;