I4G10DaysOfCodeChallenge: My thought process while solving the Palindrome leetcode problem
Problem Statement for Day3
Given an integer x, return true if x is a palindrome integer.
An integer is a palindrome when it reads the same backward as forward.
Approach:
The first step is to create a base case which is when the length of the integer is equal to 1. When this case is encountered, the function returns true because a single-digit integer is a palindrome.
When the integer isn't a single digit integer, we initialized a for loop with a range equal to half the length of the integer, this is because we would be carrying out a comparison of the ends of the integer and would only need to loop n/2 times(where n is the size of the integer).
On each iteration, we compare the ends using this statement
x[i] == x[~i]
When the loop is exited successfully with all comparisons evaluating to true, we return True confirming that the integer is indeed a palindrome.
if a comparison evaluates to False, the loop ends and returns False.
Below is the code snippet