Monday, 24 December 2018

Divide nd Conuer Palindrome counting


Solution: find the middle element of the string. Check to see if rule 1 n  2 applies to the string expanding from the middle element and return 1 if found or 0 if not found. then recursively call the left and right substring without the middle element and add all elements the match into the counter. return the counter

                                                         vcdcd.   ( check if d, cdc, vcdcd are valid )    
                     vc (check v and _vc are valid)                                   cd (check d, _dc are valid)
                                (check c)                                                            (check d)



No comments:

Post a Comment