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 ...
随机推荐
- CrawlSpider模板
crawlSpider 创建CrawlSpider模板 scrapy genspider -t crawl <爬虫名字> <域名> 模板代码示例: # -*- coding: ...
- js·逻辑运算
|| 遇到第一个为真就返回 && 遇到第一个为假就终止,返回false,如果没遇到就返回最后那一个 5&&4&&2&&1 ==> ...
- Big Event in HDU HDU - 1171
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1171 题意:给出每个物体的价值和物体的数量,如何分使得A,B所得价值最接近并且A的价值不能小于B 思路 ...
- 用雷达统计成绩单、numpy、matplotlib的使用
#e19.1DrawRadar import numpy as np import matplotlib.pyplot as plt import matplotlib matplotlib.rcPa ...
- postgresql 最大连接数相关
PG中有一张表记录着当前有多少连接 表名:pg_stat_activity 查询当前连接数: select count(1) from pg_stat_activity; 查询最大连接数 show m ...
- JavaList列表的一些方法
import java.util.ArrayList;import java.util.Iterator;import java.util.List; public class Test1 { pub ...
- Eclipse 中快捷键
Ctrl + Shift + T 查看原生类定义
- Java 静态代码的作用
public student{ private static int MAXNUM=100; static{ System.out.println(MAXNUM); } student(){ Syst ...
- c++中嵌入python
c++ 中嵌入python : https://blog.csdn.net/yiyouxian/article/category/6324494 Python C 和线程 :http://www. ...
- devC++代码格式化对齐的快捷键
devC++代码格式化对齐的快捷键是ctrl + shift + a ctrl + 左右键可以使光标移动一个单词的距离 shirt + 左右键可以选中光标左右的一个字符