字节9.5后端笔试,求第三题最大数解
A了0.4
我的代码大致如下
public static int getMax(int[] a, int n, int k) { int pre = 0, last = k - 1, sum = 0; while (last >= 0) { int mx = pre; for (int i = pre; i < n - last; i++) { if (a[i] > a[mx]) { mx = i; } } sum = sum * 10 + a[mx]; pre = mx + 1; last--; } return sum; }