File tree Expand file tree Collapse file tree 3 files changed +78
-0
lines changed Expand file tree Collapse file tree 3 files changed +78
-0
lines changed Original file line number Diff line number Diff line change @@ -107,6 +107,50 @@ public:
107107};
108108```
109109
110+ ### **TypeScript**
111+
112+ ```ts
113+ function firstUniqChar(s: string): string {
114+ const map = new Map();
115+ for (const c of s) {
116+ map.set(c, !map.has(c));
117+ }
118+ for (const c of s) {
119+ if (map.get(c)) {
120+ return c;
121+ }
122+ }
123+ return ' ';
124+ }
125+ ```
126+
127+ ### ** Rust**
128+
129+ ``` rust
130+ use std :: collections :: HashMap ;
131+
132+ impl Solution {
133+ pub fn first_uniq_char (s : String ) -> char {
134+ let mut map = HashMap :: new ();
135+ let s = s . chars (). collect :: <Vec <char >>();
136+ for c in s . iter () {
137+ match map . contains_key (c ) {
138+ true => map . insert (c , false ),
139+ false => map . insert (c , true ),
140+ };
141+ }
142+ for c in s . iter () {
143+ if let Some (is_single ) = map . get (c ) {
144+ if * is_single {
145+ return * c ;
146+ }
147+ }
148+ }
149+ ' '
150+ }
151+ }
152+ ```
153+
110154### ** ...**
111155
112156```
Original file line number Diff line number Diff line change 1+ use std:: collections:: HashMap ;
2+
3+ impl Solution {
4+ pub fn first_uniq_char ( s : String ) -> char {
5+ let mut map = HashMap :: new ( ) ;
6+ let s = s. chars ( ) . collect :: < Vec < char > > ( ) ;
7+ for c in s. iter ( ) {
8+ match map. contains_key ( c) {
9+ true => map. insert ( c, false ) ,
10+ false => map. insert ( c, true ) ,
11+ } ;
12+ }
13+ for c in s. iter ( ) {
14+ if let Some ( is_single) = map. get ( c) {
15+ if * is_single {
16+ return * c;
17+ }
18+ }
19+ }
20+ ' '
21+ }
22+ }
Original file line number Diff line number Diff line change 1+ function firstUniqChar ( s : string ) : string {
2+ const map = new Map ( ) ;
3+ for ( const c of s ) {
4+ map . set ( c , ! map . has ( c ) ) ;
5+ }
6+ for ( const c of s ) {
7+ if ( map . get ( c ) ) {
8+ return c ;
9+ }
10+ }
11+ return ' ' ;
12+ }
You can’t perform that action at this time.
0 commit comments