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;
    }
};
相关推荐
Rain的Java大神之路26 分钟前
面了 50 个候选人,90% 都挂在 LeetCode 3 无重复字符的最长子串:滑动窗口的 5 个致命坑
java·后端·leetcode
文丑颜不良啊12 小时前
LeetCode876~900题目解析
java·leetcode
木井巳21 小时前
【动态规划: 路径问题】不同路径
java·算法·leetcode·动态规划
晒太羊的猫1 天前
hot100子串
java·算法·leetcode
海清河晏1111 天前
加油站问题
数据结构·算法·leetcode
Nuanyt1 天前
LeetCode Hot 100 · 双指针 3 题 Java
java·笔记·算法·leetcode·双指针
文丑颜不良啊1 天前
LeetCode851~875题目解析
java·leetcode
Navigator_Z1 天前
LeetCode //C - 1304. Find N Unique Integers Sum up to Zero
c语言·算法·leetcode
?abc!2 天前
(数组)581. 最短无序连续子数组
数据结构·算法·leetcode
hold?fish:palm2 天前
40 二叉树的直径
c++·leetcode