当前位置:网站首页>面试题 01.04. 回文排列-辅助数组法
面试题 01.04. 回文排列-辅助数组法
2022-07-18 02:42:00 【Mr Gao】
面试题 01.04. 回文排列
给定一个字符串,编写一个函数判定其是否为某个回文串的排列之一。
回文串是指正反两个方向都一样的单词或短语。排列是指字母的重新排列。
回文串不一定是字典当中的单词。
示例1:
输入:“tactcoa”
输出:true(排列有"tacocat"、“atcocta”,等等)
将其转化为数组并从小到大排序
判断每个字母重复的次数
每个字母重复偶数次记为0,重复奇数次记为1;push进数组count
对count进行求和
若结果>1则有两个或以上的单词重复奇数次 输出false;其与输出true;
bool canPermutePalindrome(char* s){
int r[128];
int i=0;
for(i=0;i<128;i++){
r[i]=0;
}
i=0;
while(s[i]!='\0'){
r[s[i]]++;
i++;
}
int count=0;
for(i=0;i<128;i++){
if(r[i]%2!=0){
count++;
}
}
if(count>1){
return false;
}
return true;
}
边栏推荐
- Vs2019 list control control self drawing routine inherits CListCtrl class onnmcustomdraw redrawing
- 使用深度学习制作机器人大脑图纸
- Realization of communication between ROS and stm32
- MySQL 正則錶達式
- Mycat2 start message [mycat-3036][err_init_config] start filemetadatastoragemanager fail
- Vs2019 MFC dynamically creates edit control, csliderctrl class member function create application creates slider control control [mfc dynamically creates control 4]
- JMeter 21 天打卡 day08
- 软件设计师:11-基础知识例题
- 05.位图和比较器的简单应用
- Torus material mask
猜你喜欢
![[C language] 10000 word document operation summary](/img/3b/8f6c9b464f2b0c30c12fc91ad915e2.png)
[C language] 10000 word document operation summary

CANoe:.vmodule文件是什么

epoll相关函数和结构介绍以及服务器开发流程

The fourth day of MATLAB learning (decision statement)

如何下载ScienceDirect(Elsevier)文献的补充材料

Software testing training is unreliable? Spent 3W on software testing and didn't find a job for half a year?

The IPO of Aoyang technology was terminated: the annual revenue was 800million, and Su Wei held 67.5% equity

Vs2019 MFC slider control control inherits csliderctrl class to redraw self paint

STM32中断梅开二度(一)

CSDN認證C1級別學習筆記 - Web進階篇
随机推荐
STM32中断梅开二度(一)
【Unity3D】UGUI之Dropdown
Expressions régulières MySQL
VS2019 MFC动态创建EDIT控件 ,CSliderCtrl类成员函数Create应用创建Slider Control控件[MFC动态创建控件四]
Deep learning environment configuration pytoch
Spichi rushes to the scientific innovation board: annual revenue of 300million and loss of 340million. Alibaba and Lenovo star are shareholders
Entropy technology passed the registration: the annual revenue was 1.955 billion, and the book balance of accounts receivable was 290million
WCF——实现带认证的服务及常见报错
06. Binary tree and simple application
What is graph neural network?
JMeter 21 day clock in day13
Latex basic grammar summary
数据湖(十三):Spark与Iceberg整合DDL操作
JMeter 21 天打卡 day09
YoloV7:基于自己训练的模型如何导出正确的ONNX
记录使用mRemoteNG软件启动后无法进行复制粘贴
Explore Alibaba cloud IOT development board 1-haas 100
MATLAB学习第四天(决策语句)
Deep learning environment configuration tensorflow2+keras
groovy学习