-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f8a638
commit b1eb9a0
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
func isPalindrome(x int) bool { | ||
rev := 0 | ||
tmp := x | ||
|
||
//loop until tmp is 0 | ||
for tmp > 0 { | ||
//use mod 10 to get last digit | ||
ld := tmp % 10 | ||
//reverse the number | ||
rev = rev*10 + ld | ||
//divide tmp by 10 | ||
tmp = tmp / 10 | ||
} | ||
|
||
//is x a palindrome number? | ||
if x == rev { | ||
return true | ||
} | ||
return false | ||
} |