Solving LeetCode 179 Largest Number with Custom Sorting

🚀 Day 32 of #100DaysOfCode Solved LeetCode 179 – Largest Number 🔢 Today’s problem was a great reminder that sorting isn’t always straightforward. Instead of normal numeric sorting, the trick is to compare numbers based on their string concatenation order. 💡 Key Insight: To decide order between two numbers a and b, compare: ab vs ba Whichever forms the larger number should come first. 🔍 What I learned: Custom sorting using comparators Converting integers to strings for flexible comparison Edge case handling (like leading zeros → return "0") ⚡ Approach: Convert integers to strings Sort using (b+a).compareTo(a+b) logic Build the final result using StringBuilder 💻 Efficient and clean solution with strong real-world relevance in greedy + sorting problems #100DaysOfCode #DSA #LeetCode #Java #CodingJourney #ProblemSolving #Algorithms #DSAwithEdSlash @edslash

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories