Yaswanth Kumar D’s Post

❄️ takeUforward — Day 38 ✅ A Number After a Double Reversal | Number Manipulation | LeetCode Today I worked on a number manipulation problem involving reversing digits twice and checking if the result equals the original number. 💡 Problem Statement Given an integer "num", reverse the number twice and check whether the final value is equal to the original number. 🧠 Approach • Store the original number. • Reverse the number using modulo ("% 10") and division ("// 10"). • Reverse the result again. • Compare the final value with the original number. 🐍 Python Code class Solution: def isSameAfterReversals(self, num: int) -> bool: orginal = num sum_ = 0 sum2 = 0 while num > 0: last_digit = num % 10 sum_ = (sum_ * 10) + last_digit num //= 10 while sum_ > 0: lsd = sum_ % 10 sum2 = (sum2 * 10) + lsd sum_ //= 10 return True if sum2 == orginal else False ⏱ Complexity • Time: O(d) — where d is number of digits • Space: O(1) 📌 Key Learning Reversing numbers using digit extraction helps build strong fundamentals in number-based algorithms and edge case handling. 🚀 Day 38 completed — improving number manipulation skills step by step. #Python #DSA #LeetCode #ProblemSolving #CodingJourney #LearningInPublic #100DaysOfCode

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories