Already in Order

Before using binary search or displaying data neatly, it is often important to check whether a list is already ordered. The function is_sorted receives a list of numbers nums and returns True if the numbers are sorted in non-decreasing order: each next element is not smaller than the previous one. An empty list and a one-element list count as sorted.

Примеры

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

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

def is_sorted(nums: list[int]) -> bool:

Теги

liststwo-pointers
PostgreSQLv16

Aici va apărea rezultatul execuției codului

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