题目路径:

3264. K 次乘运算后的最终数组 I

个人解法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public class Solution {
public int[] getFinalState(int[] nums, int k, int multiplier) {
for (int i=0;i<k;i++){
fun1(nums,multiplier);
}
return nums;
}

// 获取最小值并乘以 multiplier
public void fun1(int[] nums, int multiplier) {
int index = 0;
for (int i = 1; i < nums.length; i++) {
if (nums[index] > nums[i]) {
index = i;
}
}
nums[index] = nums[index] * multiplier;
}
}