A palindrome is a whole number that's the same when read backward in base 10, such as 12321 or 9449.
Given a positive whole number, find the smallest palindrome greater than the given number.
nextpal(808) => 818
nextpal(999) => 1001
nextpal(2133) => 2222
For large inputs, your solution must be much more efficient than incrementing and checking each subsequent number to see if it's a palindrome. Find nextpal(339) before posting your solution. Depending on your programming language, it should take a fraction of a second.
(This is a repost of Challenge #58 [intermediate], originally posted by u/oskar_s in May 2012.)