博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[LeetCode] Valid Palindrome
阅读量:7064 次
发布时间:2019-06-28

本文共 674 字,大约阅读时间需要 2 分钟。

The suggested solution to this problem has given a clear idea. The tricky part of this problem is to handle all the edge cases carefully and write a clean code.

The following code should be self-explanatory. Note that the use of toupper avoid some messy if-else statements.

1 class Solution { 2 public: 3     bool isPalindrome(string s) { 4         int l = 0, r = s.length() - 1; 5         while (l < r) { 6             while (l < r && !isalnum(s[l])) l++; 7             if (l >= r) break; 8             while (r > l && !isalnum(s[r])) r--; 9             if (toupper(s[l++]) != toupper(s[r--]))10                 return false;11         }12         return true;13     }14 };

 

转载地址:http://tqill.baihongyu.com/

你可能感兴趣的文章
Hyper-V 2节点集群高可用的限制
查看>>
Silverlight Navigation导航框架实例系列汇总
查看>>
走近复杂数据库计算型软件的设计与制作(3)—视图的设计
查看>>
域用户权限|运行软件
查看>>
如何解决双显示器显示B/S架构软件的问题
查看>>
Android笔记:Wake Lock
查看>>
简单易用的headless浏览器
查看>>
编写shell脚本的另一种方法
查看>>
产品设计体会(2012)另一种产品版本细分策略
查看>>
企业WIFI安全应用方案
查看>>
修改eclipse自动生成的comments中的author名字
查看>>
路由基础概念解析
查看>>
oracle 中删除表 drop delete truncate 的区别
查看>>
轻巧的网络流量实时监控工具NTOPNG
查看>>
Exchange 2013部署系列之(八)邮箱、通讯组创建及规划
查看>>
贪心初步-A - Doing Homework again
查看>>
[CTO札记]盛大文学公司名称对联
查看>>
AD DS最佳实践分析程序(BPA)应用实例---扫描并归档结果
查看>>
RAC 开启gsd和oc4j服务
查看>>
MYSQL 动态变量赋值不对的情况
查看>>