有三种方法,1朴素
2kmp2次拓展
3动态规划。
既然要设计栈就是朴素了
for i=1 to str.len
if str[i]<>zhan[zhantop] then
inc(zhantop)
zhan[zhantop]=str[i]
else
pd=true
while pd do
dec(zhantop)
inc(duitop)
duilie[duitop]=zhan[zhantop]
if zhan[zhantop]<>str[i] then pd=false
大概就这样,
2kmp2次拓展
3动态规划。
既然要设计栈就是朴素了
for i=1 to str.len
if str[i]<>zhan[zhantop] then
inc(zhantop)
zhan[zhantop]=str[i]
else
pd=true
while pd do
dec(zhantop)
inc(duitop)
duilie[duitop]=zhan[zhantop]
if zhan[zhantop]<>str[i] then pd=false
大概就这样,
