Maximum Average Subarray I Solutions in C++Number 643Difficulty EasyAcceptance 41.5%Link LeetCodeOther languages PythonSolutionsC++ solution by haoel/leetcode// Source : https://leetcode.com/problems/maximum-average-subarray-i/description/// Author : Hao Chen// Date : 2018-04-19 class Solution {public: double findMaxAverage(vector<int>& nums, int k) { int sum=0; for(int i=0; i<k; i++ ) { sum += nums[i]; } int s = sum; for (int i=k; i< nums.size(); i++) { s += nums[i]; s -= nums[i-k]; if (s > sum) { sum = s; } } return (double)sum/k; }};// Source : https://leetcode.com/problems/maximum-average-subarray-i/description/ // Author : Hao Chen // Date : 2018-04-19 class Solution { public: double findMaxAverage(vector<int>& nums, int k) { int sum=0; for(int i=0; i<k; i++ ) { sum += nums[i]; } int s = sum; for (int i=k; i< nums.size(); i++) { s += nums[i]; s -= nums[i-k]; if (s > sum) { sum = s; } } return (double)sum/k; } };