Skip to content

Commit ebde25f

Browse files
authored
Create remove-adjacent-almost-equal-characters.py
1 parent 29ecfd9 commit ebde25f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
# greedy
5+
class Solution(object):
6+
def removeAlmostEqualCharacters(self, word):
7+
"""
8+
:type word: str
9+
:rtype: int
10+
"""
11+
result = 0
12+
for i in xrange(len(word)-1):
13+
if (i+1)+result >= len(word):
14+
break
15+
if abs(ord(word[(i+1)+result])-ord(word[i+result])) <= 1:
16+
result += 1
17+
return result

0 commit comments

Comments
 (0)