Asked 5 months ago
0Comments
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 ;
}
};
Share