【LeetCode#125】三种解法

LeetCode#125LeetCode项目地址:持续更新ing… (欢迎催更)思路回文串最常见3种解法:双指针、栈、字符串反转双指针PS:面试中不建议用正则,因为考察不出你的水平,面试官肯定还会问别的方法实现过滤 public static boolean isPalindrome2(String s) {// 过滤非字母数字字符, \\W ==> [^a-zA-Z0-9],面试时用正则可能还会问另一种方法 String str = s.repla
摘要由CSDN通过智能技术生成

LeetCode#125

思路

回文串最常见3种解法:双指针、栈、字符串反转

双指针

  • PS:面试中不建议用正则,因为考察不出你的水平,面试官肯定还会问别的方法实现过滤
    public static boolean isPalindrome2(String s) {
   

// 过滤非字母数字字符, \\W ==>  [^a-zA-Z0-9],面试时用正则可能还会问另一种方法
        String str = s.replaceAll("\\W", "");
        // 双指针
        int start = 0, end = str.length() - 1;
        while (start < end) {
   
            if (Character.toUpperCase(str.charAt(start)) != Character.toUpperCase(str.c
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值