Reverse Words in a String Java Solution

Day 23 ✅ — still showing up every day. #100DaysOfCode | LeetCode 151 – Reverse Words in a String Looks easy on the surface. Reverse the words in a string. Simple, right? Not quite. The tricky part? The input can have leading spaces, trailing spaces, AND multiple spaces between words — but the output should be clean with single spaces only. My Java solution: — Trim the input — Split by space — Loop backwards, skip empty strings from the split — Build the result using StringBuilder Final runtime: 5ms | Beats 86.54% 🎯 Honest takeaway: This problem reminded me that edge cases are where real programming lives. It's not just about getting the logic right — it's about thinking about what can go wrong. 23 days in. 77 to go. Let's keep building. 🙌 #LeetCode #DSA #Java #100DaysOfCode #DailyChallenge #CodeNewbie #TechCommunity

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories