Python Code Cover Image

Is It a Palindrome Number? Three Ways to Solve It Without Converting to String

🧩 The Problem Given an integer x, determine whether it’s a palindrome — that is, whether it reads the same forwards and backwards. 🔗 Problem Link: LeetCode 9. Palindrome Number Examples Input: x = 121 → Output: True Input: x = -121 → Output: False Input: x = 10 → Output: False Bonus: Can you solve it without converting the integer to a string? 🔍 The Three Approaches I Explored 1. 💡 Direct Solution with String Conversion def isPalindrome(x: int) -> bool: return str(x) == str(x)[::-1] Simple and fast (4 ms on LeetCode) But does not satisfy the follow-up constraint of avoiding strings 2. 📐 Mathematical Reversal Using log10 and Closed-Form Formula Inspired by this StackExchange post, this solution uses a formula to reverse digits without strings: ...

July 6, 2025 · 2 min · Frederico Gago
Python Cover Image

My First Post

Introduction In this post, we’ll explore some new features in Python 3.13. What’s New Feature 1 Feature 2 Conclusion Python 3.13 brings valuable improvements. More in future posts!

June 24, 2025 · 1 min · Frederico Gago