java.lang.Object
g0801_0900.s0831_masking_personal_information.Solution

public class Solution extends Object
831 - Masking Personal Information.<p>Medium</p> <p>You are given a personal information string <code>s</code>, representing either an <strong>email address</strong> or a <strong>phone number</strong>. Return <em>the <strong>masked</strong> personal information using the below rules</em>.</p> <p><strong>Email address:</strong></p> <p>An email address is:</p> <ul> <li>A <strong>name</strong> consisting of uppercase and lowercase English letters, followed by</li> <li>The <code>'@'</code> symbol, followed by</li> <li>The <strong>domain</strong> consisting of uppercase and lowercase English letters with a dot <code>'.'</code> somewhere in the middle (not the first or last character).</li> </ul> <p>To mask an email:</p> <ul> <li>The uppercase letters in the <strong>name</strong> and <strong>domain</strong> must be converted to lowercase letters.</li> <li>The middle letters of the <strong>name</strong> (i.e., all but the first and last letters) must be replaced by 5 asterisks <code>&quot;*****&quot;</code>.</li> </ul> <p><strong>Phone number:</strong></p> <p>A phone number is formatted as follows:</p> <ul> <li>The phone number contains 10-13 digits.</li> <li>The last 10 digits make up the <strong>local number</strong>.</li> <li>The remaining 0-3 digits, in the beginning, make up the <strong>country code</strong>.</li> <li><strong>Separation characters</strong> from the set <code>{'+', '-', '(', ')', ' '}</code> separate the above digits in some way.</li> </ul> <p>To mask a phone number:</p> <ul> <li>Remove all <strong>separation characters</strong>.</li> <li>The masked phone number should have the form: <ul> <li><code>&quot;***-***-XXXX&quot;</code> if the country code has 0 digits.</li> <li><code>&quot;+*-***-***-XXXX&quot;</code> if the country code has 1 digit.</li> <li><code>&quot;+**-***-***-XXXX&quot;</code> if the country code has 2 digits.</li> <li><code>&quot;+***-***-***-XXXX&quot;</code> if the country code has 3 digits.</li> </ul> </li> <li><code>&quot;XXXX&quot;</code> is the last 4 digits of the <strong>local number</strong>.</li> </ul> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;[email protected]&rdquo;</p> <p><strong>Output:</strong> &ldquo;l*****[email protected]&rdquo;</p> <p><strong>Explanation:</strong> s is an email address.</p> <p>The name and domain are converted to lowercase, and the middle of the name is replaced by 5 asterisks.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;[email protected]&rdquo;</p> <p><strong>Output:</strong> &ldquo;a*****[email protected]&rdquo;</p> <p><strong>Explanation:</strong> s is an email address.</p> <p>The name and domain are converted to lowercase, and the middle of the name is replaced by 5 asterisks.</p> <p>Note that even though &ldquo;ab&rdquo; is 2 characters, it still must have 5 asterisks in the middle.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;1(234)567-890&rdquo;</p> <p><strong>Output:</strong> &ldquo;***-***-7890&rdquo;</p> <p><strong>Explanation:</strong> s is a phone number.</p> <p>There are 10 digits, so the local number is 10 digits and the country code is 0 digits.</p> <p>Thus, the resulting masked number is &ldquo;***-***-7890&rdquo;.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>s</code> is either a <strong>valid</strong> email or a phone number.</li> <li>If <code>s</code> is an email: <ul> <li><code>8 <= s.length <= 40</code></li> <li><code>s</code> consists of uppercase and lowercase English letters and exactly one <code>'@'</code> symbol and <code>'.'</code> symbol.</li> </ul> </li> <li>If <code>s</code> is a phone number: <ul> <li><code>10 <= s.length <= 20</code></li> <li><code>s</code> consists of digits, spaces, and the symbols <code>'('</code>, <code>')'</code>, <code>'-'</code>, and <code>'+'</code>.</li> </ul> </li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details