leetcode每日刷题计划-简单篇day12
Num 125 验证回文串 Valid Palindrome
非常有收货的一道题嘻嘻嘻,本来是考试期间划水挑的题,坑点有点多
第一个是注意对temp1和temp2中途更新的判断
第二个是字符串频繁的作为参数出现,一次又一次的出现会爆内存,使用const string &s这样不复制(奇怪len等于0并不会报错,好像是因为之前复制的本来是string满的,不小心复制多了一对“”,然后爆string了)
还有就是专门有函数将字符串里面的大小写进行转换的
class Solution {
public:
bool ischar(int a,const string & s)
{
int x=(int)s[a];
if((x>= && x<=)||(x>= && x<=) || (x>= && x<=))
return true;
return false;
}
bool same(int a1,int a2,const string & s)
{
int x1=(int)s[a1];
int x2=(int)s[a2];
if(x1==x2)
return true;
if(abs(x1-x2)== && x1>= && x2>=)
return true;
return false;
}
bool isPalindrome(string s) {
int temp1,temp2;
temp1=;
temp2=s.length()-;
while(temp1<temp2)
{
while(!ischar(temp1,s))
{
temp1++;
if(temp1>=temp2)
return true;
}
while(!ischar(temp2,s))
{
temp2--;
if(temp1>=temp2)
return true;
}
cout<<temp1<<" "<<temp2<<endl;
if(temp1>=temp2)
return true;
if(!same(temp1,temp2,s))
return false;
temp1++;
temp2--;
}
return true;
}
};
leetcode每日刷题计划-简单篇day12的更多相关文章
- leetcode每日刷题计划-简单篇day5
刷题成习惯以后感觉挺好的 Num 27 移除元素 Remove Element 跟那个排序去掉相同的一样,len标记然后新的不重复的直接放到len class Solution { public: i ...
- leetcode每日刷题计划-简单篇day3
收到swe提前批面试hhh算是ep挂了的后续 努力刷题呀争取今年冲进去! Num 21 合并两个有序链表 Merge Two Sorted Lists 注意新开的链表用来输出结果的是ListNode ...
- leetcode每日刷题计划-简单篇day1
orzorz开始刷题 争取坚持每周平均下来简单题一天能做两道题吧 非常简单的题奇奇怪怪的错误orz越不做越菜 Num 7 整数反转 Reverse Integer 刚开始多给了一个变量来回折腾占地方, ...
- leetcode每日刷题计划-简单篇day10
跳题,不熟悉的留到周末再做. 保持冷静,不信画饼. num 100 相同的树 Same Tree 做法可能不是特别简洁,注意一下.最后判断完子树以后,要确定根的数值是一样的 然后在isleaf的判定先 ...
- leetcode每日刷题计划-简单篇day9
Num 38 报数 Count and Say 题意读起来比较费劲..看懂了题还是不难的 注意最后的长度是sz的长度,开始写错写的len 在下次计算的时候len要更新下 说明 直接让char和int进 ...
- leetcode每日刷题计划-简单篇day6
突发奇想&胡思乱想的一天 银行家算法证明错了并挂在黑板上的可怜希希 Num 53 最大子序和 Maximum Subarray O(n)的算法实现了,分治法有空补 class Solution ...
- leetcode每日刷题计划-简单篇day2
今天数模比赛爆肝&操作系统大作业 脖子疼orz先把题过了保证flag不倒..个别细节回头看吧 Num 13 罗马数字转整数 Roman to Integer 一遍提交过,开始编译出了点问题 具 ...
- leetcode每日刷题计划-简单篇day13
Num 169 先码,回头再说,摩尔算法... tle了 class Solution { public: int majorityElement(vector<int>& num ...
- leetcode每日刷题计划-简单篇day11
Num 121 买卖股票的最佳时期 Best Time to Buy and Sell Stock class Solution { public: int maxProfit(vector<i ...
随机推荐
- Spring ConditionalOnProperty
Spring Annotation @ConditionalOnProperty spring doc解释 @Conditional: Indicates that a component is on ...
- ES6的一些知识学习
一.基础 ES6 - 类: class A{ constructor(name,color){ this.name = name; this.color = color; } toString(){ ...
- JavaScript作用域(第七天)
我们都知道js代码是由自上而下的执行,但我们来看看下面的代码: test(); function test(){ console.log("hello world"); }; 如果 ...
- gdb 调试 python
gdb 版本 >7 的 对python调试有特别支持,参考: https://docs.python.org/devguide/gdb.html?highlight=gdb https://bl ...
- CS萌新的汇编学习之路02 Learning of Assembly Language
第二节课 寄存器 1. 寄存器的定义: 进行信息储存的器件,是CPU中程序员可以读写的部件,通过改变各种寄存器中的内容来实现对CPU的控制 2. 寄存器的种类: 本节课学习通用寄存器和段寄存器 2. ...
- 用理论告诉你 三极管和MOS管的区别在哪
在电路设计当中假设我们想要对电流中止控制,那就少不了三极管的帮助.我们俗称的三极管其全称为半导体三极管,它的主要作用就是将微小的信号中止放大.MOS管与三极管有着许多相近的地方,这就使得一些新手不断无 ...
- 用 EPWA 写一个 图片播放器 PicturePlayer
用 EPWA 写一个 图片播放器 PicturePlayer . 有关 EPWA,见 <我发起并创立了一个 EPWA 的 开源项目> https://www.cnblogs.com ...
- [转载]使用QTP测试Windows对象
Desktop对象的使用: 通过Desktop对象,可以访问Windows的桌面顶层对象.Desktop对象包括CaptureBitmap.ChildObjects.RunAnalog方法. (1) ...
- Redis 5.0.3集群部署
参考文章 https://blog.csdn.net/yyTomson/article/details/85783753 https://www.cnblogs.com/zy-303/p/102731 ...
- ubuntu设置 SSH 通过密钥对登录
1. 制作密钥对 首先在服务器上制作密钥对.登录到打算使用密钥登录的账户,然后执行以下命令: [root@host ~]$ ssh-keygen <== 建立密钥对 Generating pub ...