Posts

Leetcode 1147. Longest Chunked Palindrome Decomposition - Rolling hash O(n) Solution

key concept: " (factor*(a mod b)) mod b "  equl  " (factor*a) mod b " " (factor*a + b) mod c " equl " (factor*(a mod c) + b ) mod c"   < pre > < code class = 'html' > class Solution { public:     int longestDecomposition ( string text )     {         auto myHash = []( char ch )         {             return hash < char >{} ( ch ) ;         };         if ( text . size () == 1 )             return 1 ;         int left = 0 ;         int right = text . size () - 1 ;         int len = 1 ;         int ans = 0 ;         size_t lHash = 0 ;         size_t rHash = 0 ;         int prime = 1e9 + 7 ;         while ( left < r...