-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidPalindrome.py
More file actions
35 lines (30 loc) · 818 Bytes
/
Copy pathvalidPalindrome.py
File metadata and controls
35 lines (30 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
###############
#680 LC Valid Palindrome II
class Solution:
def isPal(self, s):
self.s = s
beg = 0
end = len(s)-1
for _ in range(len(s)):
if s[beg] != s[end]:
return False
beg += 1
end -= 1
return True
def validPalindrome(self, s):
n = len(s)
beg = 0
end = n-1
if (n % 2 != 0):
print(self.isPal(s))
elif(n % 2 == 0):
newS =[]
for i in range(len(s)):
if s[beg] != s[end]:
newS = s.replace(s[end], "")
break
beg += 1
end -= 1
print(self.isPal(newS))
op = Solution()
op.validPalindrome('abcdba')