You are given a non-negative integer n. Your task is to return the number formed by swapping its first and last digits, while keeping all the digits in between in their original order.
If the number contains only one digit, return it unchanged.
Input: n = 1234
Output: 4231
Explanation: The first digit, 1, and the last digit, 4, are exchanged, producing 4231.
Input: n = 5005
Output: 5005
Explanation: The first and last digits are both 5, so swapping them leaves the number unchanged.
Input: n = 7
Output: 7
Explanation: A single-digit number has the same first and last digit, so it remains unchanged.
Sign in to write, run, and submit your solution against the full test suite.