|
1 | 1 | # [831.Masking Personal Information][title] |
2 | 2 |
|
3 | | -> [!WARNING|style:flat] |
4 | | -> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm) |
5 | | -
|
6 | 3 | ## Description |
| 4 | +You are given a personal information string `s`, representing either an **email address** or a **phone number**. Return the **masked** personal information using the below rules. |
| 5 | + |
| 6 | +**Email address**: |
| 7 | + |
| 8 | +An email address is: |
| 9 | + |
| 10 | +- A **name** consisting of uppercase and lowercase English letters, followed by |
| 11 | +- The `'@'` symbol, followed by |
| 12 | +- The **domain** consisting of uppercase and lowercase English letters with a dot `'.'` somewhere in the middle (not the first or last character). |
| 13 | + |
| 14 | +To mask an email: |
| 15 | + |
| 16 | +- The uppercase letters in the **name** and **domain** must be converted to lowercase letters. |
| 17 | +- The middle letters of the **name** (i.e., all but the first and last letters) must be replaced by 5 asterisks `"*****"`. |
| 18 | + |
| 19 | +**Phone number**: |
| 20 | + |
| 21 | +A phone number is formatted as follows: |
| 22 | + |
| 23 | +- The phone number contains 10-13 digits. |
| 24 | +- The last 10 digits make up the **local number**. |
| 25 | +- The remaining 0-3 digits, in the beginning, make up the **country code**. |
| 26 | +- **Separation characters** from the set `{'+', '-', '(', ')', ' '}` separate the above digits in some way. |
| 27 | + |
| 28 | +To mask a phone number: |
| 29 | + |
| 30 | +- Remove all **separation characters**. |
| 31 | +- The masked phone number should have the form: |
| 32 | + |
| 33 | + - `"***-***-XXXX"` if the country code has 0 digits. |
| 34 | + - `"+*-***-***-XXXX"` if the country code has 1 digit. |
| 35 | + - `"+**-***-***-XXXX"` if the country code has 2 digits. |
| 36 | + - `"+***-***-***-XXXX"` if the country code has 3 digits. |
| 37 | + |
| 38 | +- `"XXXX"` is the last 4 digits of the **local number**. |
| 39 | + |
7 | 40 |
|
8 | 41 | **Example 1:** |
9 | 42 |
|
10 | 43 | ``` |
11 | | -Input: a = "11", b = "1" |
12 | | -Output: "100" |
| 44 | +Input: s = "LeetCode@LeetCode.com" |
| 45 | +Output: "l*****e@leetcode.com" |
| 46 | +Explanation: s is an email address. |
| 47 | +The name and domain are converted to lowercase, and the middle of the name is replaced by 5 asterisks. |
13 | 48 | ``` |
14 | 49 |
|
15 | | -## 题意 |
16 | | -> ... |
17 | | -
|
18 | | -## 题解 |
| 50 | +**Example 2:** |
19 | 51 |
|
20 | | -### 思路1 |
21 | | -> ... |
22 | | -Masking Personal Information |
23 | | -```go |
24 | 52 | ``` |
| 53 | +Input: s = "AB@qq.com" |
| 54 | +Output: "a*****b@qq.com" |
| 55 | +Explanation: s is an email address. |
| 56 | +The name and domain are converted to lowercase, and the middle of the name is replaced by 5 asterisks. |
| 57 | +Note that even though "ab" is 2 characters, it still must have 5 asterisks in the middle. |
| 58 | +``` |
| 59 | + |
| 60 | +**Example 3:** |
25 | 61 |
|
| 62 | +``` |
| 63 | +Input: s = "1(234)567-890" |
| 64 | +Output: "***-***-7890" |
| 65 | +Explanation: s is a phone number. |
| 66 | +There are 10 digits, so the local number is 10 digits and the country code is 0 digits. |
| 67 | +Thus, the resulting masked number is "***-***-7890". |
| 68 | +``` |
26 | 69 |
|
27 | 70 | ## 结语 |
28 | 71 |
|
|
0 commit comments