forked from computiq/GIZ-pass-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython-pass.py
More file actions
28 lines (26 loc) · 732 Bytes
/
python-pass.py
File metadata and controls
28 lines (26 loc) · 732 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
s = "babad"
class Solution:
@staticmethod
def longest_palindromic(s: str) -> str:
res = ""
resLen = 0
for i in range(len(s)):
# odd length
l , r = i,i
while l >= 0 and r < len(s) and s[l] == s[r]:
if ( r - l + 1 ) > resLen :
res = s [l:r+1]
resLen = r - l + 1
l -= 1
r += 1
# even length
l , r = i,i + 1
while l >= 0 and r < len(s) and s[l] == s[r]:
if (r - l + 1 ) > resLen :
res = s[l:r+1]
resLen = r - 1 + 1
l -= 1
r += 1
return res
result = Solution.longest_palindromic(s)
print(result)