Skip to content

Commit 68809b7

Browse files
authored
Create 2957-remove-adjacent-almost-equal-characters.js
1 parent 1402d71 commit 68809b7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @param {string} word
3+
* @return {number}
4+
*/
5+
var removeAlmostEqualCharacters = function(word) {
6+
const n = word.length, { abs } = Math
7+
8+
let res = 0
9+
for(let i = 1; i < n;) {
10+
const delta = abs(word.charCodeAt(i) - word.charCodeAt(i - 1))
11+
if(delta <= 1) {
12+
res++
13+
i += 2
14+
} else i++
15+
16+
}
17+
18+
return res
19+
};

0 commit comments

Comments
 (0)