Add Digits Java Solution LeetCode 258

🚀 LeetCode #258 – Add Digits | Java Solution Another quick but insightful problem solved today! 💡 📌 Problem Statement Given an integer num, repeatedly add all its digits until the result becomes a single digit. 🔍 Example Input: 38 3 + 8 = 11 1 + 1 = 2 Output: 2 💻 Approach I Used (Iterative) Keep summing digits using % 10 and / 10 Repeat until the number becomes a single digit while (num >= 10) { int sum = 0; while (num != 0) { sum += num % 10; num = num / 10; } num = sum; } return num; 🧠 Key Learning Breaking numbers using modulo & division Looping until a condition is satisfied Understanding digit manipulation 📈 Small problems like this sharpen your thinking for bigger optimizations. Happy Coding 😊 #LeetCode #Java #DSA #ProblemSolving #CodingJourney #100DaysOfCode #Algorithms

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories