Matching Edges

Checking the first and last elements is useful when a list should start and end with the same value. Write a function same_first_last that takes a list of numbers nums. Return True if the list is not empty and its first element equals its last element. If the list is empty or the edge values are different, return False.

Примеры

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

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

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

Теги

listsarray
PostgreSQLv16

Tukaj bo rezultat izvajanja kode

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