Exploring more Leetcode problems - #Day3

Checking palindrome numbers (I4G 10 Days of Code Challenge)

Compared to the last two days, the challenge of today was particularly easy as it did not require any changing of the input itself but more of confirmation of a particular condition

The Challenge

3_question.png

My Approach

Thankfully, the challenge description is very straightforward and did not require too much thought. Basically, the approach I used was to first create a reversed version of the given number, compare whether the given number is the same as the reversed number and then return either true or false based on the condition. The algorithm looks something like this:

number = // some number
reversed_number = reverse(number)
if(reversed_number == number){
  return true
}else{
  return false
}

Specific information

I believe one of the reasons for which this challenge was easier was because of the language of choice for these challenges. PHP comes with a lot of functions that support working on numbers including functions for reversing. The greatest advantage was that the PHP reversing functions is not limited to just strings but also numbers, retaining the output of the function also as a number.

3_accepted.png Another day, another challenge completed!