No result illustrationNo result illustration

DevLoom

search

Lets Connect

chevron right
Menu
Home

Home

Community

Community

Blog Posts

Blog Posts

Programming

Programming

Tech Topics

Tech Topics

Explore

Explore

Find Jobs

Find Jobs

Tags

Tags

DevLoomPerfect Place for devs
    profile

    Jubair

    upvoteupvote

    0

    downvote

    0

    star

    Palindromic Substrings

    clock icon

    Asked 11 months ago

    message

    0Comments

    eye

    0 Views

    class Solution {
    public:
        int expandAroundIndex( string s  , int i , int j ){
            int count  = 0 ;
    
            while( i >= 0 && j < s.length() && s[i] == s[j] ){ //match !
                count++ ;
                   i-- ;
                   j++ ;
    
            }
            return count ;
    
        }
        int countSubstrings(string s) {
            int count  =  0 ;
            int size  = s.length()  ;
    
    
            for(int i = 0 ; i < size  ;  i++){
                //ODD CSSE 
                int oddCase = expandAroundIndex(s , i , i) ; 
                count = count + oddCase ;
                
                //EVEN CASE
    
                int evenCase = expandAroundIndex(s , i , i+1) ;
                count = count + evenCase ;
            }
            return count ;
            
            
        }
    };
    Palindrome
    Strings
    LeetCode
    medium

    Share

    Write your comment here !

    0 Responses