Suppose we have a string s, we have to check whether all its palindromic substrings have odd lengths or not.
So, if the input is like s = "level", then the output will be True
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
class Solution: def solve(self, s): for i in range(1, len(s)): if s[i] == s[i - 1]: return False return True ob = Solution() s = "level" print(ob.solve(s))