Skip to content

Commit 9c2e5e7

Browse files
authored
feat: add js solution to lc problem: No.1704 (doocs#980)
1 parent 47cb74d commit 9c2e5e7

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

solution/1700-1799/1704.Determine if String Halves Are Alike/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,24 @@ class Solution {
193193
}
194194
```
195195

196+
### **JavaScript**
197+
198+
```js
199+
/**
200+
* @param {string} s
201+
* @return {boolean}
202+
*/
203+
var halvesAreAlike = function (s) {
204+
const str = 'aeiouAEIOU';
205+
let cnt = 0;
206+
for (let i = 0; i < s.length / 2; i++) {
207+
if (str.indexOf(s[i]) > -1) cnt++;
208+
if (str.indexOf(s[s.length - 1 - i]) > -1) cnt--;
209+
}
210+
return cnt === 0;
211+
};
212+
```
213+
196214
### **...**
197215

198216
```

solution/1700-1799/1704.Determine if String Halves Are Alike/README_EN.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,24 @@ class Solution {
177177
}
178178
```
179179

180+
### **JavaScript**
181+
182+
```js
183+
/**
184+
* @param {string} s
185+
* @return {boolean}
186+
*/
187+
var halvesAreAlike = function (s) {
188+
const str = 'aeiouAEIOU';
189+
let cnt = 0;
190+
for (let i = 0; i < s.length / 2; i++) {
191+
if (str.indexOf(s[i]) > -1) cnt++;
192+
if (str.indexOf(s[s.length - 1 - i]) > -1) cnt--;
193+
}
194+
return cnt === 0;
195+
};
196+
```
197+
180198
### **...**
181199

182200
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @param {string} s
3+
* @return {boolean}
4+
*/
5+
var halvesAreAlike = function (s) {
6+
const str = 'aeiouAEIOU';
7+
let cnt = 0;
8+
for (let i = 0; i < s.length / 2; i++) {
9+
if (str.indexOf(s[i]) > -1) cnt++;
10+
if (str.indexOf(s[s.length - 1 - i]) > -1) cnt--;
11+
}
12+
return cnt === 0;
13+
};

0 commit comments

Comments
 (0)