Skip to content

Commit 7e9ef55

Browse files
Qiu-ITyanglbme
authored andcommitted
feat: add js solution to lc problem: No.2068
1 parent 38caa55 commit 7e9ef55

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

solution/2000-2099/2068.Check Whether Two Strings are Almost Equivalent/README.md

+23
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,29 @@ class Solution {
203203
}
204204
```
205205

206+
### **JavaScript**
207+
208+
```js
209+
/**
210+
* @param {string} word1
211+
* @param {string} word2
212+
* @return {boolean}
213+
*/
214+
var checkAlmostEquivalent = function (word1, word2) {
215+
const m = new Map();
216+
for (let i = 0; i < word1.length; i++) {
217+
m.set(word1[i], (m.get(word1[i]) || 0) + 1);
218+
m.set(word2[i], (m.get(word2[i]) || 0) - 1);
219+
}
220+
for (const v of m.values()) {
221+
if (Math.abs(v) > 3) {
222+
return false;
223+
}
224+
}
225+
return true;
226+
};
227+
```
228+
206229
### **...**
207230

208231
```

solution/2000-2099/2068.Check Whether Two Strings are Almost Equivalent/README_EN.md

+23
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,29 @@ class Solution {
196196
}
197197
```
198198

199+
### **JavaScript**
200+
201+
```js
202+
/**
203+
* @param {string} word1
204+
* @param {string} word2
205+
* @return {boolean}
206+
*/
207+
var checkAlmostEquivalent = function (word1, word2) {
208+
const m = new Map();
209+
for (let i = 0; i < word1.length; i++) {
210+
m.set(word1[i], (m.get(word1[i]) || 0) + 1);
211+
m.set(word2[i], (m.get(word2[i]) || 0) - 1);
212+
}
213+
for (const v of m.values()) {
214+
if (Math.abs(v) > 3) {
215+
return false;
216+
}
217+
}
218+
return true;
219+
};
220+
```
221+
199222
### **...**
200223

201224
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @param {string} word1
3+
* @param {string} word2
4+
* @return {boolean}
5+
*/
6+
var checkAlmostEquivalent = function (word1, word2) {
7+
const m = new Map();
8+
for (let i = 0; i < word1.length; i++) {
9+
m.set(word1[i], (m.get(word1[i]) || 0) + 1);
10+
m.set(word2[i], (m.get(word2[i]) || 0) - 1);
11+
}
12+
for (const v of m.values()) {
13+
if (Math.abs(v) > 3) {
14+
return false;
15+
}
16+
}
17+
return true;
18+
};

0 commit comments

Comments
 (0)