DEV Community

Ezekiel nwuguru
Ezekiel nwuguru

Posted on

DAY 3: Palindrom number

Hey! It's day 3 of I4G 10 days coding challenge. Today's task was to write a code that checks if an integer is a palindrome number. A palindrome number is number that gives the same result when reversed.

*Strategy: *

  • Definition of problem: I need to understand what the problem is before diving into the solution. To achieve I made research on google of what a palindrome number is.
  • Algorithm: Having understood the problem I wrote an algorithm to help me narrow down the problem into solution. The Algorithm is as shown below:

Algorithm:

  • Declare three integer variables: remainder, original and reverse
  • Initialize reverse to 0 and set original to the given integer
  • Set a while loop with condition: x(given integer) != 0
  • while the condition is true set remainder = x % 10, reverse = reverse * 10 + remainder and x = x / 10
  • Return true if reverse is same original else return false

Check out the complete code here: Palindrome Number - LeetCode https://leetcode.com/problems/palindrome-number/submissions/

Top comments (0)