831. Masking Personal Information Medium

@problem@discussion
#String



1/**
2 * [831] Masking Personal Information
3 *
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 * <u>Email address:</u>
6 * An email address is:
7 * 
8 * 	A name consisting of uppercase and lowercase English letters, followed by
9 * 	The '@' symbol, followed by
10 * 	The domain consisting of uppercase and lowercase English letters with a dot '.' somewhere in the middle (not the first or last character).
11 * 
12 * To mask an email:
13 * 
14 * 	The uppercase letters in the name and domain must be converted to lowercase letters.
15 * 	The middle letters of the name (i.e., all but the first and last letters) must be replaced by 5 asterisks "*****".
16 * 
17 * <u>Phone number:</u>
18 * A phone number is formatted as follows:
19 * 
20 * 	The phone number contains 10-13 digits.
21 * 	The last 10 digits make up the local number.
22 * 	The remaining 0-3 digits, in the beginning, make up the country code.
23 * 	Separation characters from the set {'+', '-', '(', ')', ' '} separate the above digits in some way.
24 * 
25 * To mask a phone number:
26 * 
27 * 	Remove all separation characters.
28 * 	The masked phone number should have the form:
29 * 	
30 * 		"***-***-XXXX" if the country code has 0 digits.
31 * 		"+*-***-***-XXXX" if the country code has 1 digit.
32 * 		"+**-***-***-XXXX" if the country code has 2 digits.
33 * 		"+***-***-***-XXXX" if the country code has 3 digits.
34 * 	
35 * 	
36 * 	"XXXX" is the last 4 digits of the local number.
37 * 
38 *  
39 * Example 1:
40 * 
41 * Input: s = "[email protected]"
42 * Output: "l*****[email protected]"
43 * Explanation: s is an email address.
44 * The name and domain are converted to lowercase, and the middle of the name is replaced by 5 asterisks.
45 * 
46 * Example 2:
47 * 
48 * Input: s = "[email protected]"
49 * Output: "a*****[email protected]"
50 * Explanation: s is an email address.
51 * The name and domain are converted to lowercase, and the middle of the name is replaced by 5 asterisks.
52 * Note that even though "ab" is 2 characters, it still must have 5 asterisks in the middle.
53 * 
54 * Example 3:
55 * 
56 * Input: s = "1(234)567-890"
57 * Output: "***-***-7890"
58 * Explanation: s is a phone number.
59 * There are 10 digits, so the local number is 10 digits and the country code is 0 digits.
60 * Thus, the resulting masked number is "***-***-7890".
61 * 
62 *  
63 * Constraints:
64 * 
65 * 	s is either a valid email or a phone number.
66 * 	If s is an email:
67 * 	
68 * 		8 <= s.length <= 40
69 * 		s consists of uppercase and lowercase English letters and exactly one '@' symbol and '.' symbol.
70 * 	
71 * 	
72 * 	If s is a phone number:
73 * 	
74 * 		10 <= s.length <= 20
75 * 		s consists of digits, spaces, and the symbols '(', ')', '-', and '+'.
76 * 	
77 * 	
78 * 
79 */
80pub struct Solution {}
81
82// problem: https://leetcode.com/problems/masking-personal-information/
83// discuss: https://leetcode.com/problems/masking-personal-information/discuss/?currentPage=1&orderBy=most_votes&query=
84
85// submission codes start here
86
87impl Solution {
88    pub fn mask_pii(s: String) -> String {
89        String::new()
90    }
91}
92
93// submission codes end
94
95#[cfg(test)]
96mod tests {
97    use super::*;
98
99    #[test]
100    fn test_831() {
101    }
102}
103


Back
© 2025 bowen.ge All Rights Reserved.