Skip to content

Commit

Permalink
647.c
Browse files Browse the repository at this point in the history
Palindromic substring using dynamic programming
  • Loading branch information
sauravkdubey authored Oct 11, 2019
1 parent 031ae5f commit e5adce3
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions leetcode/src/647.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

/* Author : Saurav Dubey */


int countSubstrings(char* s) {
int len = strlen(s);
int i;
int count = 0;
for( i=0; i<len; i++){
// cases handled for both odd and even lenghted Palindrome

count += countPalin(s, i, i, len);
if(i!=len-1)
count += countPalin(s, i, i+1, len);
}
return count;
}
int countPalin(char *s, int head, int tail, int len){
int ret = (s[head]==s[tail])? 1:0 ;
if( ret && head-1>=0 && tail+1<len)
ret += countPalin(s, head-1, tail+1, len);
return ret;
}

0 comments on commit e5adce3

Please sign in to comment.