add: leetcode 2037 solution

This commit is contained in:
tphyhFighting
2022-03-24 11:23:37 +08:00
parent e1d3d596fb
commit e5bbc2ea75

View File

@ -0,0 +1,21 @@
package leetcode
import "sort"
func minMovesToSeat(seats []int, students []int) int {
sort.Ints(seats)
sort.Ints(students)
n := len(students)
moves := 0
for i := 0; i < n; i++ {
moves += abs(seats[i], students[i])
}
return moves
}
func abs(a, b int) int {
if a > b {
return a - b
}
return b - a
}