首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >【LeetCode每日打卡】152. Maximum Product Subarray

【LeetCode每日打卡】152. Maximum Product Subarray

作者头像
韩旭051
发布2020-06-23 10:44:32
发布2020-06-23 10:44:32
4320
举报
文章被收录于专栏:刷题笔记刷题笔记

Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome.

Example 1: Input: "aba" Output: True Example 2: Input: "abca" Output: True Explanation: You could delete the character 'c'. Note: The string will only contain lowercase characters a-z. The maximum length of the string is 50000.

来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/valid-palindrome-ii 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

判断回文字符串 双指针 java解决

两头相会

代码语言:javascript
复制
class Solution {
    public boolean validPalindrome(String s) {
    for(int i = 0, j = s.length()-1; i < j ; i++, j--){
        if(s.charAt(i) != s.charAt(j)){
            //分两种情况,一是右边减一,二是左边加一
            return isPalindrome(s,i,j-1) || isPalindrome(s, i+1, j);
        }
    }
    return true;
}

public boolean isPalindrome(String s, int i, int j) {
    while (i < j) {
        if (s.charAt(i++) != s.charAt(j--)) {
            return false;
        }
    }
    return true;
}
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/05/19 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 判断回文字符串 双指针 java解决
  • 两头相会
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档