Skip to content

Commit

Permalink
Create ispalindrome.go
Browse files Browse the repository at this point in the history
  • Loading branch information
rerichardjr authored Sep 26, 2023
1 parent 4f8a638 commit b1eb9a0
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions ispalindrome.go
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
}

0 comments on commit b1eb9a0

Please sign in to comment.