Skip to content

Commit

Permalink
Create 2957_Remove_Adjacent_Almost-Equal_Characters.java
Browse files Browse the repository at this point in the history
  • Loading branch information
mkhuzaima committed Dec 24, 2023
1 parent 05a85f6 commit 292832e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions 2957_Remove_Adjacent_Almost-Equal_Characters.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// id: 2957
// Name: Remove Adjacent Almost-Equal Characters
// link: https://leetcode.com/problems/remove-adjacent-almost-equal-characters
// Difficulty: Medium

class Solution {
public int removeAlmostEqualCharacters(String word) {
int count = 0;
for (int i = 1; i < word.length(); i++) {
if (Math.abs(word.charAt(i) - word.charAt(i-1)) <= 1) {
i++;
count++;
}
}

return count;
}
}

0 comments on commit 292832e

Please sign in to comment.