Skip to content

Commit 292832e

Browse files
authored
Create 2957_Remove_Adjacent_Almost-Equal_Characters.java
1 parent 05a85f6 commit 292832e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// id: 2957
2+
// Name: Remove Adjacent Almost-Equal Characters
3+
// link: https://leetcode.com/problems/remove-adjacent-almost-equal-characters
4+
// Difficulty: Medium
5+
6+
class Solution {
7+
public int removeAlmostEqualCharacters(String word) {
8+
int count = 0;
9+
for (int i = 1; i < word.length(); i++) {
10+
if (Math.abs(word.charAt(i) - word.charAt(i-1)) <= 1) {
11+
i++;
12+
count++;
13+
}
14+
}
15+
16+
return count;
17+
}
18+
}

0 commit comments

Comments
 (0)