Reformat Phone Number — LeetCode
Jan 17, 2021
Question:
Solution:
- Clean the input
- iterate while length is > 4, appending to blocks in groups of 3
- if the length of the remaining string is ≤3, append it
- if the length of the remaining string is anything else (i.e. 4), add in blocks of length 2.
- Return blocks joined by ‘-’.
Source code here.
Social links here.