Always One Direction

A monotonic list keeps moving in one direction: it either never decreases or never increases. Equal neighboring values are allowed, so steps like 2, 2 do not break the pattern. Given nums, return True if it is monotonic, otherwise return False.

Примеры

Ввод
[1, 2, 2, 3]
Вывод
True
Ввод
[6, 5, 4, 4]
Вывод
True
Ввод
[1, 3, 2]
Вывод
False

Нужно реализовать

def is_monotonic(nums):

Теги

array
PostgreSQLv16

Hawn jidher ir-riżultat tat-tħaddim tal-kodiċi

Visible tests
1
Input
[1,2,2,3]
ExpectedTrue
2
Input
[6,5,4,4]
ExpectedTrue
3
Input
[1,3,2]
ExpectedFalse
4
Input
[1,1,1]
ExpectedTrue
5
Input
[1]
ExpectedTrue
6
Input
[1,2,4,5,0]
ExpectedFalse
Focus radio
Paused · SomaFM · Fluid