Problem
Sort Real Number Strings
Learn this problemProblem statement
You are given a list of strings. Each string represents a real number and may be positive, negative, or contain a decimal point.
Sort the strings by their numeric values without converting the full string to an arithmetic numeric data type.
Return the sorted list of original strings. If two strings represent the same numeric value, keep their original relative order.
Function
sortRealNumberStrings(numbers: String[]) → String[]Examples
Example 1
numbers = ["10","-3.5","2.01","0"]return = ["-3.5","0","2.01","10"]The strings are ordered by numeric value: -3.5 < 0 < 2.01 < 10.
Example 2
numbers = ["-1.25","-1.2","3","0.5","12.01"]return = ["-1.25","-1.2","0.5","3","12.01"]Among negative values, -1.25 is smaller than -1.2.