Leetcode Note: Go - Can Make Arithmetic Progression From Sequence

Can Make Arithmetic Progression From Sequence - LeetCode
https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence/

  • Go 言語で取り組んだメモ

回答

Golang solution faster than 100% with explanation - Can Make Arithmetic Progression From Sequence - LeetCode
https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence/solutions/1065502/golang-solution-faster-than-100-with-explanation/

func canMakeArithmeticProgression(arr []int) bool {
	sort.Ints(arr)
	difference := arr[1] - arr[0] // starting difference

	for i := 1; i < len(arr) - 1; i++ {
		if arr[i + 1] - arr[i] != difference { // sliding window
			return false
		}
	}
	return true
}