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的更多相关文章

  1. leetcode每日刷题计划-简单篇day5

    刷题成习惯以后感觉挺好的 Num 27 移除元素 Remove Element 跟那个排序去掉相同的一样,len标记然后新的不重复的直接放到len class Solution { public: i ...

  2. leetcode每日刷题计划-简单篇day3

    收到swe提前批面试hhh算是ep挂了的后续 努力刷题呀争取今年冲进去! Num 21 合并两个有序链表 Merge Two Sorted Lists 注意新开的链表用来输出结果的是ListNode ...

  3. leetcode每日刷题计划-简单篇day1

    orzorz开始刷题 争取坚持每周平均下来简单题一天能做两道题吧 非常简单的题奇奇怪怪的错误orz越不做越菜 Num 7 整数反转 Reverse Integer 刚开始多给了一个变量来回折腾占地方, ...

  4. leetcode每日刷题计划-简单篇day10

    跳题,不熟悉的留到周末再做. 保持冷静,不信画饼. num 100 相同的树 Same Tree 做法可能不是特别简洁,注意一下.最后判断完子树以后,要确定根的数值是一样的 然后在isleaf的判定先 ...

  5. leetcode每日刷题计划-简单篇day9

    Num 38 报数 Count and Say 题意读起来比较费劲..看懂了题还是不难的 注意最后的长度是sz的长度,开始写错写的len 在下次计算的时候len要更新下 说明 直接让char和int进 ...

  6. leetcode每日刷题计划-简单篇day6

    突发奇想&胡思乱想的一天 银行家算法证明错了并挂在黑板上的可怜希希 Num 53 最大子序和 Maximum Subarray O(n)的算法实现了,分治法有空补 class Solution ...

  7. leetcode每日刷题计划-简单篇day2

    今天数模比赛爆肝&操作系统大作业 脖子疼orz先把题过了保证flag不倒..个别细节回头看吧 Num 13 罗马数字转整数 Roman to Integer 一遍提交过,开始编译出了点问题 具 ...

  8. leetcode每日刷题计划-简单篇day13

    Num 169 先码,回头再说,摩尔算法... tle了 class Solution { public: int majorityElement(vector<int>& num ...

  9. leetcode每日刷题计划-简单篇day11

    Num 121 买卖股票的最佳时期 Best Time to Buy and Sell Stock class Solution { public: int maxProfit(vector<i ...

随机推荐

  1. multi-label image classification:多标签图像分类总结

    多标签图像分类总结 目录 1.简介 2.现有数据集和评价指标 3.学习算法 4.总结(现在存在的问题,研究发展的方向) 简介 传统监督学习主要是单标签学习,而现实生活中目标样本往往比较复杂,具有多个语 ...

  2. 设置table的每竖的宽度

  3. centos的nginx如何访问本地共享文件夹的文件 nginx访问404,403问题

    关键挂载 sudo vmhgfs-fuse .host:/musings /home/xxx -o allow_other,uid=0,gid=0

  4. C++中关于字符串的一些API

    参考资料:http://www.runoob.com/cplusplus/cpp-strings.html 一.前言 不管是在编写何种语言程序,需要从输入设备中获取数据的需求很频繁,在这类频繁的应用场 ...

  5. 16. Antimalware (反病毒 3个)

    Malwarebytes反恶意软件是为Windows的恶意软件扫描程序. 作者声称使用各种技术来查找其他恶意软件扫描仪检测不到的恶意软件. 有一个有限选项的免费试用版和支持能够运行扫描计划的完整版本, ...

  6. django登录逻辑

    django-restframework中已经实现了登录逻辑,只需要安装配置就可以使用 pip install djangorestframework-jwt REST_FRAMEWORK = { ' ...

  7. 跳台阶(JAVA)

    跳台阶 题目描述 一只青蛙一次可以跳上1级台阶,也可以跳上2级.求该青蛙跳上一个n级的台阶总共有多少种跳法. 思路:典型的动态规划问题,动态规划问题最关键的是把事件中的各种情形抽象为状态,然后找到前后 ...

  8. vue中父组件给子组件额外添加参数

    1 子组件: this.$emit('callbackone',item.parentId) 2 父组件: @callbackone="callbackone($event,index)&q ...

  9. Spring MVC的原理及配置详解

    网址链接:https://www.cnblogs.com/baiduligang/p/4247164.html

  10. Python3 多线程例子

    import threading, zipfile class AsyncZip(threading.Thread): def __init__(self, infile, outfile): thr ...