Skip to content

Commit

Permalink
[LeetCode] valid-palindrome-ii
Browse files Browse the repository at this point in the history
  • Loading branch information
ehdgua01 committed Sep 11, 2024
1 parent e7ac73c commit 01385d1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Empty file.
27 changes: 27 additions & 0 deletions coding_test/leetcode/valid_palindrome_2/solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Solution:
def validPalindrome(self, s: str) -> bool:
i, j = 0, len(s) - 1
while i < j:
if s[i] != s[j]:
left, right = s[i + 1 : j + 1], s[i:j]
return left == left[::-1] or right == right[::-1]
i += 1
j -= 1
return True


def test_valid_palindrome():
s = Solution()
assert s.validPalindrome("aba")
assert s.validPalindrome("a")
assert s.validPalindrome("aab")
assert not s.validPalindrome("aabb")
assert s.validPalindrome("abcba")
assert s.validPalindrome("abca")
assert s.validPalindrome("abccbba")
assert s.validPalindrome("deeee")
assert not s.validPalindrome("eeccccbebaeeabebccceea")
assert s.validPalindrome("deddde")
assert s.validPalindrome(
"aguokepatgbnvfqmgmlcupuufxoohdfpgjdmysgvhmvffcnqxjjxqncffvmhvgsymdjgpfdhooxfuupuculmgmqfvnbgtapekouga"
)
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ norecursedirs = dev_matching delivery_hero

[flake8]
exclude = venv
max-line-length = 88
max-line-length = 120
ignore =
E203,
E225,
Expand Down

0 comments on commit 01385d1

Please sign in to comment.