Leetcode 3194. 最小元素和最大元素的最小平均值

原题链接:Leetcode 3194. 最小元素和最大元素的最小平均值




注意,(nums[l]+nums[r])要除以2.0而不是2,才是浮点型

cpp 复制代码
class Solution {
public:
    double minimumAverage(vector<int>& nums) {
        sort(nums.begin(),nums.end());
        int l=0,r=nums.size()-1;
        double averages=100.0;
        while(l<r){
            averages=min((nums[l]+nums[r])/2.0,averages);
            l++;
            r--;
        }
        return averages;
    }
};
相关推荐
Navigator_Z11 小时前
LeetCode //C - 1278. Palindrome Partitioning III
c语言·算法·leetcode
青山木14 小时前
Hot 100 --- 编辑距离
java·数据结构·算法·leetcode·动态规划
All for pursuit.17 小时前
【回溯-4】46.全排列
数据结构·c++·算法·leetcode
All for pursuit.20 小时前
【回溯-5】78.子集
数据结构·c++·算法·leetcode
代码什么用1 天前
LeetCode-560.和为 K 的子数组
算法·leetcode
All for pursuit.1 天前
【回溯-3】39.组合总和
数据结构·c++·算法·leetcode
yi0111 天前
DAY19: LeetCode 28 找出字符串中第一个匹配项的下标
人工智能·笔记·python·算法·leetcode
不会就选b1 天前
算法日常・每日刷题--<动态规划>6
数据结构·算法·leetcode
0+1112 天前
算法 --模拟
c++·算法·leetcode
Nil2082 天前
leetcode 739每日温度
算法·leetcode·职场和发展