#529 Minimum Number Without Leading Zeroes
A string s containing only digits from 0 through 9 is given, and not all of its elements are equal to 0. Rearrange its digits so that the number represented by the string is as small as possible and the string contains no leading zeroes.
A number contains leading zeroes when the number is not zero but starts with the digit 0. For example, 01 and 0303 contain leading zeroes, while 0 and 30000 do not.
Input:
-
A string
s, where1 <= |s| <= 9; - The string is guaranteed to contain at least one non-zero digit.
Output:
- A string representing the minimum possible number without leading zeroes.
Examples:
"682902" -> "202689"
"01" -> "10"
public static String solve(String s) {
// TODO
}
Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor