Skip to content

Commit 7a16a83

Browse files
committed
feat: add ts solution to lc problem: No.0884
No.0884.Uncommon Words from Two Sentences
1 parent cc6eb0b commit 7a16a83

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

solution/0800-0899/0884.Uncommon Words from Two Sentences/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,24 @@ class Solution {
8787

8888
```
8989

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+
90108
### **C++**
91109

92110
```cpp

solution/0800-0899/0884.Uncommon Words from Two Sentences/README_EN.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,24 @@ class Solution {
9696

9797
```
9898

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+
99117
### **C++**
100118

101119
```cpp
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
};

0 commit comments

Comments
 (0)