def last(data: List[Any]): Any = {
if(data.size < 1)
throw new IllegalArgumentException("List is too short")
else
return data.last
}
def penultimate(data: List[Any]): Any = {
if(data.size < 2)
throw new IllegalArgumentException("List is too short")
else
return data(data.size-2);
}
def nth(index: Int, data: List[Any]): Any = {
if(data.size < index - 1)
throw new IllegalArgumentException("Index is out of Range")
else
return data(index)
}
def length(data: List[Any]): Int = {
return data.size
}
def reverse(data: List[Any]): List[Any] = {
return data.reverse
}
Solution to S-99 ( P01 ~ P05 )
最新推荐文章于 2024-09-16 15:45:27 发布