We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
给定 n 个整数,找出平均数最大且长度为 k 的连续子数组,并输出该最大平均数。
输入:[1,12,-5,-6,50,3], k = 4 输出:12.75 解释:最大平均数 (12-5-6+50)/4 = 51/4 = 12.75
来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/maximum-average-subarray-i 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
The text was updated successfully, but these errors were encountered:
挺简单的,没什么可说的,就是有一点,go语言进行浮点运算,需要把两个变量都转换成浮点数之后再运算
func findMaxAverage(nums []int, k int) float64 { var sum, ret int left,right := 0, k for i := left; i < right; i++ { sum += nums[i] } ret = sum for right < len(nums) { sum = sum - nums[left] + nums[right] if sum > ret { ret = sum } left++ right++ } return float64(ret)/float64(k) }
Sorry, something went wrong.
No branches or pull requests
给定 n 个整数,找出平均数最大且长度为 k 的连续子数组,并输出该最大平均数。
示例:
提示:
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/maximum-average-subarray-i
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
The text was updated successfully, but these errors were encountered: