Sort Strings Lexicographically
EasyP3Coding
Sort an array of lowercase strings in dictionary (lexicographic) order and return it.
Compare strings character by character; the first differing character decides. If one string is a prefix of the other, the shorter one comes first. Duplicates are kept.
Example 1
- Input
- words = ["pear","apple","fig"]
- Output
- ["apple","fig","pear"]
Example 2
- Input
- words = ["ab","a","abc"]
- Output
- ["a","ab","abc"]
Example 3
- Input
- words = ["b","b"]
- Output
- ["b","b"]
Constraints
- 0 <= words.length <= 10^4
- 1 <= words[i].length <= 50
- words[i] consists of lowercase English letters
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 9. ⌘Enter runs, ⌘⇧Enter submits.