LeetCode3264[K次乘运算后的最终数组I]

题目

链接

LeetCode3264[K次乘运算后的最终数组I]

详情

实例

实例1

实例2

提示

题解

思路

先找到最小值

然后对最小值进行操作

最后输出容器

代码

class Solution {
public:

    int findVecMinNumIndex(vector<int> nums)//找出最小值的下标
    {
        int i = 0, iMin = nums.at(0), iMinIndex = 0;
        for (i = 0; i < nums.size(); i++)
        {
            if (iMin > nums.at(i))
            {
                iMinIndex = i;
                iMin = nums.at(i);
            }
        }

        return iMinIndex;
    }

    vector<int> getFinalState(vector<int>& nums, int k, int multiplier) {
        
        for (int i = 0; i < k; i++)
        {
            int iIndex = findVecMinNumIndex(nums);
            nums.at(iIndex) *= multiplier; //操作
        }

        return nums;
    }
};

 

posted @   EricsT  阅读(8)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
点击右上角即可分享
微信分享提示