Reformat Phone Number — LeetCode

Soren Rood
Jan 17, 2021

Question:

LeetCode # 1694

Solution:

Solution
  1. Clean the input
  2. iterate while length is > 4, appending to blocks in groups of 3
  3. if the length of the remaining string is ≤3, append it
  4. if the length of the remaining string is anything else (i.e. 4), add in blocks of length 2.
  5. Return blocks joined by ‘-’.

Source code here.

Social links here.

--

--