Skip to content

Commit 38385f7

Browse files
committed
feat: add solutions to lc problem: No.0831
1 parent 8acf35e commit 38385f7

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

solution/0800-0899/0831.Masking Personal Information/README.md

+24
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,30 @@ func maskPII(s string) string {
227227
}
228228
```
229229

230+
### **TypeScript**
231+
232+
```ts
233+
function maskPII(s: string): string {
234+
const i = s.indexOf('@');
235+
if (i !== -1) {
236+
let ans = s[0].toLowerCase() + '*****';
237+
for (let j = i - 1; j < s.length; ++j) {
238+
ans += s.charAt(j).toLowerCase();
239+
}
240+
return ans;
241+
}
242+
let t = '';
243+
for (const c of s) {
244+
if (/\d/.test(c)) {
245+
t += c;
246+
}
247+
}
248+
const cnt = t.length - 10;
249+
const suf = `***-***-${t.substring(t.length - 4)}`;
250+
return cnt === 0 ? suf : `+${'*'.repeat(cnt)}-${suf}`;
251+
}
252+
```
253+
230254
### **...**
231255

232256
```

solution/0800-0899/0831.Masking Personal Information/README_EN.md

+24
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,30 @@ func maskPII(s string) string {
196196
}
197197
```
198198

199+
### **TypeScript**
200+
201+
```ts
202+
function maskPII(s: string): string {
203+
const i = s.indexOf('@');
204+
if (i !== -1) {
205+
let ans = s[0].toLowerCase() + '*****';
206+
for (let j = i - 1; j < s.length; ++j) {
207+
ans += s.charAt(j).toLowerCase();
208+
}
209+
return ans;
210+
}
211+
let t = '';
212+
for (const c of s) {
213+
if (/\d/.test(c)) {
214+
t += c;
215+
}
216+
}
217+
const cnt = t.length - 10;
218+
const suf = `***-***-${t.substring(t.length - 4)}`;
219+
return cnt === 0 ? suf : `+${'*'.repeat(cnt)}-${suf}`;
220+
}
221+
```
222+
199223
### **...**
200224

201225
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function maskPII(s: string): string {
2+
const i = s.indexOf('@');
3+
if (i !== -1) {
4+
let ans = s[0].toLowerCase() + '*****';
5+
for (let j = i - 1; j < s.length; ++j) {
6+
ans += s.charAt(j).toLowerCase();
7+
}
8+
return ans;
9+
}
10+
let t = '';
11+
for (const c of s) {
12+
if (/\d/.test(c)) {
13+
t += c;
14+
}
15+
}
16+
const cnt = t.length - 10;
17+
const suf = `***-***-${t.substring(t.length - 4)}`;
18+
return cnt === 0 ? suf : `+${'*'.repeat(cnt)}-${suf}`;
19+
}

0 commit comments

Comments
 (0)