Leetcode-5150 Longest Chunked Palindrome Decomposition(段式回文)
Posted asurudo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode-5150 Longest Chunked Palindrome Decomposition(段式回文)相关的知识,希望对你有一定的参考价值。
1 #define _for(i,a,b) for(int i = (a);i < b;i ++) 2 3 bool judge(string s,int i,int j,int len) 4 5 _for(k,0,len) 6 if(s[i]!=s[j]) 7 return false; 8 else 9 i ++,j ++; 10 return true; 11 12 class Solution 13 14 public: 15 int longestDecomposition(string text) 16 17 int i = 0; 18 int j = text.size()-1; 19 int lastj = j; 20 int rnt = 0; 21 while(i<j) 22 23 if(text[i]==text[j] && judge(text,i,j,lastj-j+1)) 24 25 rnt ++; 26 i += lastj-j+1; 27 lastj = j-1; 28 29 j --; 30 31 rnt *= 2; 32 if(i<=j) 33 rnt ++; 34 return rnt; 35 36 ;
以上是关于Leetcode-5150 Longest Chunked Palindrome Decomposition(段式回文)的主要内容,如果未能解决你的问题,请参考以下文章
winform 怎么把2次查询的数据放在同一个dataGridView中
Longest Palindromic Substring & Longest Palindromic Subsequence
[Lintcode]124. Longest Consecutive Sequence/[Leetcode]128. Longest Consecutive Sequence