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

Example 1:

  1. Input: "aba"
  2. Output: True

Example 2:

  1. Input: "abca"
  2. Output: True
  3. Explanation: You could delete the character 'c'.

Note:

  1. The string will only contain lowercase characters a-z. The maximum length of the string is 50000.
  1. class Solution {
  2. public:
  3. bool validPalindrome(string s) {
  4. int i,j;
  5. int si,sj;
  6. int n=s.size();
  7. int count=;
  8. int way=;
  9. for(i=,j=n-;i<j;i++,j--){
  10. if(s[i]==s[j])
  11. continue;
  12. else{
  13. if(way==){
  14. return false;
  15. }
  16. if(way==){
  17. way++;
  18. i=si;
  19. j=sj;
  20. j++;
  21. }
  22. if(way==){
  23. way++;
  24. count=;
  25. si=i;
  26. sj=j;
  27. i--;
  28. }
  29. }
  30. }
  31. return true;
  32. }
  33. };

(判断是否回文)

String-680. Valid Palindrome II的更多相关文章

  1. 680. Valid Palindrome II【easy】

    680. Valid Palindrome II[easy] Given a non-empty string s, you may delete at most one character. Jud ...

  2. 【Leetcode_easy】680. Valid Palindrome II

    problem 680. Valid Palindrome II solution: 不理解判断函数中的节点的问题... class Solution { public: bool validPali ...

  3. [leetcode]680. Valid Palindrome II有效回文II(可至多删一原字符)

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

  4. [LeetCode] 680. Valid Palindrome II 验证回文字符串 II

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

  5. 680. Valid Palindrome II【Easy】【双指针-可以删除一个字符,判断是否能构成回文字符串】

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

  6. 680. Valid Palindrome II 对称字符串-可删字母版本

    [抄题]: Given a non-empty string s, you may delete at most one character. Judge whether you can make i ...

  7. LeetCode 680. Valid Palindrome II (验证回文字符串 Ⅱ)

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

  8. 【LeetCode】680. Valid Palindrome II

    Difficulty:easy  More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/valid-palindrome ...

  9. 【LeetCode】680. Valid Palindrome II 验证回文字符串 Ⅱ(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 思路来源 初版方案 进阶方案 日期 题目地址 ...

  10. 680. Valid Palindrome II

    static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...

随机推荐

  1. SECURITY_ATTRIBUTES 实现最低权限总结

    SetSecurityDescriptorDacl函数可以用来设置DACL中的信息.如果一个DACL已经在security descriptor中存在,那么此DACL将被替换.值得注意的是MSDN中的 ...

  2. MyIocp 测试截图

    根据 小猪的网络教程 学习了 IOCP 并且自己写了一个命令行版本的 客户端测试还是使用的小猪的代码 有兴趣学习IOCP的 建议去小猪的空间看看 代码思路都讲解的很清楚 推荐 http://blog. ...

  3. jquery和js中走的弯路

    1.$.each的错误用法 $.each的return xx 不能结束外层的函数,但return true/false可以 所以一般的: var result; $.each(json,functio ...

  4. 2018.10.09 NOIP模拟 世界杯(图论+set优化)

    传送门 貌似是防akakak题? 不是很清楚. 事实上如果两个人没有严格的大小关系,我们给他们两个连一条边. 这样可以构成很多连通块. 而且对于连通块a,ba,ba,b,aia_iai​和bjb_jb ...

  5. 2018.07.22 洛谷P1967 货车运输(kruskal重构树)

    传送门 这道题以前只会树剖和最小生成树+倍增. 而现在学习了一个叫做kruskal" role="presentation" style="position: ...

  6. 36 The Benefits of Marriage 结婚的益处

    36 The Benefits of Marriage 结婚的益处 ①Being sociable looks like a good way to add years to your life.Re ...

  7. 使用async-http-client实现异步批量http请求

    最近项目中需要在微服务中调用rest接口,而且需要调用得次数很多,所以同步得http客户端已经不满足要求,在网上查阅资料后发现了async-http-client这个包得性能不错,所以写了个demo测 ...

  8. MySQL终端下常用命令

    一:控制类命令 1.show variables like "%datadir%";显示注册在variables中(一个注册表key-value的格式存储数据)key能匹配%dat ...

  9. trmd_b1_ok

    # -*- coding:utf-8 -*- ''' 从11c开始提取 ''' import re import numpy as np import os year = '17A' ss=" ...

  10. 简单的Java,Python,C,C++

    Java 语言 //package main //注意不要添加包名称,否则会报错. import java.io.*; import java.util.*; cin.hasNext(); cin.h ...