File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed
solution/0800-0899/0884.Uncommon Words from Two Sentences Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,24 @@ class Solution {
87
87
88
88
```
89
89
90
+ ### ** TypeScript**
91
+
92
+ ``` ts
93
+ function uncommonFromSentences(s1 : string , s2 : string ): string [] {
94
+ let hashMap: Map <string , number > = new Map ();
95
+ for (let str of [... s1 .split (' ' ), ... s2 .split (' ' )]) {
96
+ hashMap .set (str , (hashMap .get (str ) || 0 ) + 1 );
97
+ }
98
+ let ans: Array <string > = [];
99
+ for (let [key, count] of hashMap .entries ()) {
100
+ if (count == 1 ) {
101
+ ans .push (key );
102
+ }
103
+ }
104
+ return ans ;
105
+ };
106
+ ```
107
+
90
108
### ** C++**
91
109
92
110
``` cpp
Original file line number Diff line number Diff line change @@ -96,6 +96,24 @@ class Solution {
96
96
97
97
```
98
98
99
+ ### ** TypeScript**
100
+
101
+ ``` ts
102
+ function uncommonFromSentences(s1 : string , s2 : string ): string [] {
103
+ let hashMap: Map <string , number > = new Map ();
104
+ for (let str of [... s1 .split (' ' ), ... s2 .split (' ' )]) {
105
+ hashMap .set (str , (hashMap .get (str ) || 0 ) + 1 );
106
+ }
107
+ let ans: Array <string > = [];
108
+ for (let [key, count] of hashMap .entries ()) {
109
+ if (count == 1 ) {
110
+ ans .push (key );
111
+ }
112
+ }
113
+ return ans ;
114
+ };
115
+ ```
116
+
99
117
### ** C++**
100
118
101
119
``` cpp
Original file line number Diff line number Diff line change
1
+ function uncommonFromSentences ( s1 : string , s2 : string ) : string [ ] {
2
+ let hashMap : Map < string , number > = new Map ( ) ;
3
+ for ( let str of [ ...s1 . split ( ' ' ) , ...s2 . split ( ' ' ) ] ) {
4
+ hashMap . set ( str , ( hashMap . get ( str ) || 0 ) + 1 ) ;
5
+ }
6
+ let ans : Array < string > = [ ] ;
7
+ for ( let [ key , count ] of hashMap . entries ( ) ) {
8
+ if ( count == 1 ) {
9
+ ans . push ( key ) ;
10
+ }
11
+ }
12
+ return ans ;
13
+ } ;
You can’t perform that action at this time.
0 commit comments