-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path831.py
47 lines (47 loc) · 1.98 KB
/
831.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
__________________________________________________________________________________________________
sample 24 ms submission
class Solution:
def maskPII(self, S: str) -> str:
at=S.find('@')
if at>0:
return (S[0]+'*****'+S[at-1:]).lower()
S=''.join([i for i in S if i.isdigit()])
return ["", "+*-", "+**-", "+***-"][len(S) - 10] + "***-***-" + S[-4:]
__________________________________________________________________________________________________
sample 28 ms submission
import re
class Solution:
def maskPII(self, S):
if '@' in S:
S = S.lower()
res = S.split('@')
return res[0][0] + '*****' + res[0][-1] + '@' + res[1]
else:
S = S.replace('(', '').replace(')', '').replace('-', '').replace('+', '').replace('-', '').replace(' ', '')
if len(S) == 10:
return '***-***-' + S[6:]
else:
return '+' + (len(S) - 10) * '*' + '-***-***-' + S[-4:]
def maskPII1(self, S: str) -> str:
if len(S) >= 2 and re.match(r'[a-zA-Z]+\@[a-zA-Z]+\.[a-zA-Z]+', S):
S = S.lower()
first = S[0]
second = S[S.find('@') - 1]
rest = S[S.find('@'):]
return f'{first}*****{second}{rest}'
else:
S = S.replace('(', '').replace(')', '').replace('-', '').replace('+', '').replace('-', '').replace(' ', '')
if len(S) == 10:
ans = ['***', '***', S[6:]]
return '-'.join(ans)
elif len(S) == 11:
ans = ['+*', '***', '***', S[-4:]]
return '-'.join(ans)
elif len(S) == 12:
ans = ['+**', '***', '***', S[-4:]]
return '-'.join(ans)
elif len(S) == 13:
ans = ['+***', '***', '***', S[-4:]]
return '-'.join(ans)
return S
__________________________________________________________________________________________________