Skip to content

Commit a3cf875

Browse files
committed
feat: add typescript solution to lc problem: No.0387.First Unique Character in a String
1 parent 9c78c2d commit a3cf875

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

solution/0300-0399/0387.First Unique Character in a String/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,21 @@ class Solution {
7272
}
7373
```
7474

75+
### **TypeScript**
76+
77+
```ts
78+
function firstUniqChar(s: string): number {
79+
let record = new Map();
80+
for (let cur of [...s]) {
81+
record.set(cur, record.has(cur))
82+
}
83+
for (let i =0 ; i < s.length; i++) {
84+
if (!record.get(s[i])) return i;
85+
}
86+
return -1;
87+
};
88+
```
89+
7590
### **...**
7691

7792
```

solution/0300-0399/0387.First Unique Character in a String/README_EN.md

+15
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,21 @@ class Solution {
6666
}
6767
```
6868

69+
### **TypeScript**
70+
71+
```ts
72+
function firstUniqChar(s: string): number {
73+
let record = new Map();
74+
for (let cur of [...s]) {
75+
record.set(cur, record.has(cur))
76+
}
77+
for (let i =0 ; i < s.length; i++) {
78+
if (!record.get(s[i])) return i;
79+
}
80+
return -1;
81+
};
82+
```
83+
6984
### **...**
7085

7186
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function firstUniqChar(s: string): number {
2+
let record = new Map();
3+
for (let cur of [...s]) {
4+
record.set(cur, record.has(cur))
5+
}
6+
for (let i =0 ; i < s.length; i++) {
7+
if (!record.get(s[i])) return i;
8+
}
9+
return -1;
10+
};

0 commit comments

Comments
 (0)