Skip to content

Commit b5915df

Browse files
authored
feat: add javascript solution to lcci problem: No.01.02. Check Permutation
* feat: add solutions of javascript to lcci problem
1 parent bdc1be7 commit b5915df

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

lcci/01.02.Check Permutation/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,22 @@ class Solution {
8181
}
8282
```
8383

84+
### **JavaScript**
85+
86+
```javascript
87+
var CheckPermutation = function(s1, s2) {
88+
let n1 = s1.length, n2 = s2.length;
89+
if (n1 != n2) return false;
90+
let counter = {};
91+
for (let i = 0; i < n1; i++) {
92+
let cur1 = s1.charAt(i), cur2 = s2.charAt(i);
93+
counter[cur1] = (counter[cur1] || 0) + 1;
94+
counter[cur2] = (counter[cur2] || 0) - 1;
95+
}
96+
return Object.values(counter).every(v => v == 0);
97+
};
98+
```
99+
84100
### **...**
85101

86102
```

lcci/01.02.Check Permutation/README_EN.md

+16
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ class Solution {
7979
}
8080
```
8181

82+
### **JavaScript**
83+
84+
```javascript
85+
var CheckPermutation = function(s1, s2) {
86+
let n1 = s1.length, n2 = s2.length;
87+
if (n1 != n2) return false;
88+
let counter = {};
89+
for (let i = 0; i < n1; i++) {
90+
let cur1 = s1.charAt(i), cur2 = s2.charAt(i);
91+
counter[cur1] = (counter[cur1] || 0) + 1;
92+
counter[cur2] = (counter[cur2] || 0) - 1;
93+
}
94+
return Object.values(counter).every(v => v == 0);
95+
};
96+
```
97+
8298
### **...**
8399

84100
```
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @param {string} s1
3+
* @param {string} s2
4+
* @return {boolean}
5+
*/
6+
var CheckPermutation = function(s1, s2) {
7+
let n1 = s1.length, n2 = s2.length;
8+
if (n1 != n2) return false;
9+
let counter = {};
10+
for (let i = 0; i < n1; i++) {
11+
let cur1 = s1.charAt(i), cur2 = s2.charAt(i);
12+
counter[cur1] = (counter[cur1] || 0) + 1;
13+
counter[cur2] = (counter[cur2] || 0) - 1;
14+
}
15+
return Object.values(counter).every(v => v == 0);
16+
};

0 commit comments

Comments
 (0)