当前位置: 首页 > news >正文

Golang | Leetcode Golang题解之第517题超级洗衣机

题目:

题解:

func findMinMoves(machines []int) (ans int) {tot := 0for _, v := range machines {tot += v}n := len(machines)if tot%n > 0 {return -1}avg := tot / nsum := 0for _, num := range machines {num -= avgsum += numans = max(ans, max(abs(sum), num))}return
}func abs(x int) int {if x < 0 {return -x}return x
}func max(a, b int) int {if b > a {return b}return a
}

http://www.mrgr.cn/news/60850.html

相关文章:

  • TSO的资料
  • 音视频入门基础:AAC专题(12)——FFmpeg源码中,解码AudioSpecificConfig的实现
  • 音视频入门基础:FLV专题(18)——Audio Tag简介
  • 哈希及其封装实现unordermap和set
  • Redis 分布式锁:原理、实现及最佳实践
  • redis详细教程(3.ZSet,Bitmap,HyperLogLog)
  • Python量化交易(五):量化择时策略
  • YOLO框架最新综述从YOLOV1-YOLOV11(2024年10月23)
  • Midjourney 3D:探索未来沉浸式体验的无限可能
  • ELF文件格式解读及其生成过程(上)
  • MyBatisPlus 只更新指定字段
  • argparse的基本用法
  • leetcode hot100【LeetCode 394.字符串解码】java实现
  • Vue脚手架
  • shodan5,参数使用,批量查找Mongodb未授权登录,jenkins批量挖掘
  • 前端存储IndexedDB存储方式实战案例
  • rhcsa 第二次作业
  • mysql 巧妙的索引
  • Windows Active Directory技术介绍和应用——删除计算机对象
  • GD32实战篇-移远EC800M进行TCP/UDP连接测试-上位机测试