Solved LeetCode's Length of Last Word problem in Java with simplicity and speed.

🔥 Day 45 of #100DaysOfCode 🔥 💡 Problem: Length of Last Word ✨ Approach: Trimmed the trailing spaces and used the power of lastIndexOf(' ') to pinpoint the final space — subtracting positions gives the length of the last word. Simple, clean, and blazing fast ⚡ ⚡ Complexity: Time Complexity: O(n) — linear scan through the string. Space Complexity: O(1) — no extra memory used. 📊 Result: ✔️ Accepted (60/60 test cases passed) ⚡ Runtime: 0 ms (🚀 Beats 100.00%) 💾 Memory: 41.55 MB (🔥 Beats 91.62%) 🔑 Key Insight: Elegance in code often comes from simplicity — a single line of logic can beat brute force every time 💫 #LeetCode #100DaysOfCode #Java #StringManipulation #ProblemSolving #CodingChallenge #CleanCode #DSA

  • graphical user interface, text, application, chat or text message

To view or add a comment, sign in

Explore content categories