当前位置:网站首页>PHP design function getmaxstr to find the longest symmetric string in a string - [original]
PHP design function getmaxstr to find the longest symmetric string in a string - [original]
2022-06-26 04:20:00 【Telkobe】
This is the first time I have encountered this problem , So handwriting is almost impossible for me , Because I have to debug on the machine repeatedly to get the final answer , Since I came back, I tried to write it on the computer , If there are shortcomings or simpler methods , Welcome to correct . The purpose of this problem is to write a function to find the symmetrical part of a string , Then get the longest string that meets the conditions , Like strings ‘ssabcddcba’, Then what meets the conditions is ‘abcddcba’, Let's go straight to the code .
$str='aa6aaslolsbcdeggedcbaiokabccbanh';
function getMaxStr($str){
$s_data=str_split($str);
$row=[];
foreach($s_data as $key=>$vol){
foreach($s_data as $k=>$v){
if($k<$key) continue;
if($vol==$v && $key!=$k){
if(($key+$k)==1){
$row[]=substr($str,$key,2);
}else{
$px=$key==0?$k+1:$k-$key;
$px=($px%2)==0?$px:($k-$key+1);
$px=$px/2;
for($s=1;$s<$px;$s++){
if($s_data[$key+$s]!=$s_data[$k-$s]) continue 2;
}
$row[]=substr($str,$key,($k-$key+1));
}
}
}
}
return $row;
}
$r=getMaxStr($str);
print_r($r);
边栏推荐
- Use soapUI to access the corresponding ESB project
- Etcd watch principle
- Yolov5 improvements: replace the backbone
- SQL related knowledge - constraints
- But the Internet began to have a new evolution and began to appear in a new state
- Daily tests
- Microsoft prohibits Russian users from downloading and installing win10/11
- List of provinces, cities and counties in China
- I/o virtualization technology - UIO framework
- Verrouillage de lecture et d'écriture pour la synchronisation des fils
猜你喜欢

Nailing open platform - applet development practice (nailing applet server side)

Unity移动端游戏性能优化简谱之 以引擎模块为划分的CPU耗时调优

Ten important basic principles of software debugging and testing

Zeromq from getting started to mastering
![[QT] dialog box](/img/ca/e65a0c167a4509f7c6a241870f6a32.png)
[QT] dialog box

Implementation of seven classes of BlockingQueue interface

Getting started with flask

How to use EEPROM in 51 Single Chip Microcomputer?

Tencent Interviewer: How did binder get its system services?

Knowledge of SQL - database design, backup and restore
随机推荐
Yolov5 improvements: replace the backbone
[Nuggets' operation routine disclosure] the routine of being truly Nuggets
What are the advantages and risks of paper gold investment
1064 (42000) error occurred when installing MySQL and modifying root password
微软禁止俄用户下载安装Win10/11
[QT] resource file import
Mobile terminal pull-down loading pull-down loading data
2021 year end summary
Matplotlib line chart, text display, win10
Double buffer technology asynchronous log system
Lua语法讲解
Question brushing record day01
Sorting out the examination sites of the 13th Blue Bridge Cup single chip microcomputer objective questions
Sorting out the knowledge points of the renderview renderobject parentdata of the shuttle
力扣 515. 在每个树行中找最大值
win10 系统打开的软件太小,如何变大(亲测有效)
NFT creation and binding of BSC and HT chains
线程同步之互斥量(互斥锁)
The statistics in the MySQL field become strings, and then they are converted into numbers for sorting
A brain map to summarize the needs analysis (a supplement to the actual situation at work)