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. hello1实例的分析

    JSF简介一. 什么是 JSF:JavaServer Faces (JSF) 是一种用于构建 Web 应用程序的新标准 Java 框架.它提供了一种以组件为中心来开发 Java Web 用户界面的方法 ...

  2. JavaScript基础之对象属性的检测和枚举

    属性检测 对象作为属性的集合,属性又包括自有属性和继承属性: 检测方法: \__   in运算符: \__ var obj = { x:1 } console.log( 'toString' in o ...

  3. 关于JavaScript的框架和库

    0----无所不能的JavaScript: 说到javascript,最先想到的是用于网页交互的脚本语言,这是最早netscope公司开发的基于浏览器内核的语言:但是最近几年一位大牛一chorme内核 ...

  4. vs2017 asp.net 网站发布问题 (发布路径下含源码文件)

    使用vs2010版本,网站发布后会自动将源码发不为.dll程序集,但vs2017需要进行设置,其他版本没有试过. vs2017网站发布: 1. 2. 这里给一个你想用的名字,之后它会出现在你的程序文件 ...

  5. Tenka 1 Computer Contest C-Align

    C - Align Time limit : 2sec / Memory limit : 1024MB Score : 400 points Problem Statement You are giv ...

  6. bookmarks

    嵌入式/硬件/计算机原理 PCI ID的分配 ARM汇编指令介绍 (连续4篇) https://blog.csdn.net/makethyme/article/details/1641413https ...

  7. NFPA, UL

    Who or what is NFPA? NFPA (National Fire Protection Association) is an organization in the USA that ...

  8. gcc 常用指令

    gcc hello.c    直接编译默认输出 a.out可执行文件 gcc hello.c -o hello    生成名字为hello的可执行文件 gcc hello.c -o hello -Wa ...

  9. Centos7下使用yum源安装zabbix Server

    系统:Centos7 zabbix版本:4.2   一.Zabbix Server端   1.安装仓库 rpm -ivh https://repo.zabbix.com/zabbix/4.2/rhel ...

  10. debian 安装libreoffice6.1 转换pdf

    这个东西能转,但效率不高,我已经用专门的服务器docker,速度很快,直接用curl就能返回 但这里还是记录一下直接用命令调用吧,毕竟有的老的地方这么用 && cd /usr/loca ...