Last Element

L1 Easy Arrays & Hashing
Concept
Array indexes run from 0 through count - 1, so the final element is always at count - 1. Handling the empty array is a skill on its own.
Return the last integer in nums. If the array is empty, return -1.
Examples
▸ nums = [1, 2, 3]
→ 3
▸ nums = [7]
→ 7
▸ nums = []
→ -1
Progressive Hints
Hint 1 · Nudge
The last spot of an array sits right before its size.
Hint 2 · Plan
First handle the empty case by returning -1. Otherwise return the element at index size minus 1.
Hint 3 · Approach
If the array is empty, return -1. Otherwise return nums[nums.length - 1].
Output
// Run your code to see the output here.