File tree 3 files changed +40
-0
lines changed
solution/0300-0399/0387.First Unique Character in a String
3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -72,6 +72,21 @@ class Solution {
72
72
}
73
73
```
74
74
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
+
75
90
### ** ...**
76
91
77
92
```
Original file line number Diff line number Diff line change @@ -66,6 +66,21 @@ class Solution {
66
66
}
67
67
```
68
68
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
+
69
84
### ** ...**
70
85
71
86
```
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments