mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 08:27:30 +08:00
18 lines
201 B
Go
18 lines
201 B
Go
package leetcode
|
|
|
|
func isIdealPermutation(A []int) bool {
|
|
for i := range A {
|
|
if abs(A[i]-i) > 1 {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
func abs(a int) int {
|
|
if a < 0 {
|
|
return -a
|
|
}
|
|
return a
|
|
}
|