用dfs,先发m拆分放进list里面,递归时候再取出来
public class findMax {

int max;
public int findMaxNumber(int m , int n) {
max = 0;
List<Integer> list = new LinkedList<>();
while (m > 0) {
list.add(0,m%10);
m = m/10;
}
getMax(list,0,n,0);
return 0;
}

private void getMax(List<Integer> list, int i, int n, int sum) {
if (sum > max && i == list.size()) {
max = sum;
}

for (int j = i; j < list.size(); j++) {
int a = 0;
for (int k = i; k <= j; k++) {
a = a*10 + list.get(k);
}
if (sum + a > n) {
break;
}
getMax(list, j+1, n, sum+a);
}
}
}
/*
输入:
654122
111
输出:
110
 */