![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to check whether all palindromic substrings are of odd length or not in Python
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 −
- for i in range 1 to size of s, do
- if s[i] is same as s[i - 1], then
- return False
- if s[i] is same as s[i - 1], then
- return True
Let us see the following implementation to get better understanding −
Example
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))
Input
"level"
Output
True
Advertisements