File tree 3 files changed +64
-0
lines changed
solution/2000-2099/2068.Check Whether Two Strings are Almost Equivalent
3 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -203,6 +203,29 @@ class Solution {
203
203
}
204
204
```
205
205
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
+
206
229
### ** ...**
207
230
208
231
```
Original file line number Diff line number Diff line change @@ -196,6 +196,29 @@ class Solution {
196
196
}
197
197
```
198
198
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
+
199
222
### ** ...**
200
223
201
224
```
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments