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

题目链接

方法 1:直接模拟

思路

  1. 根据题意,直接执行 k 次,每次将当前数组中最小的元素 x 替换为 x * multipler

代码

1
2
3
4
5
class Solution:
    def getFinalState(self, nums: List[int], k: int, m: int) -> List[int]:
        for _ in range(k):
            nums[nums.index(min(nums))] *= m
        return nums

复杂度

  • 时间复杂度:O(k)
  • 空间复杂度:O(1),没有用到额外的空间。
使用 Hugo 构建
主题 StackJimmy 设计