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
Accedi per vedere la cronologia degli invii
AccediAccedi per usare l'AI Mentor
AccediVisible tests
1
Input
[1,2,3]Expected
True2
Input
[3,2,1]Expected
False3
Input
[]Expected
True4
Input
[5]Expected
True5
Input
[1,1,2]Expected
True6
Input
[2,2,3]Expected
TrueFocus radio
Paused · SomaFM · Fluid