1. static int wing=[]()
  2. {
  3. std::ios::sync_with_stdio(false);
  4. cin.tie(NULL);
  5. return ;
  6. }();
  7.  
  8. class Solution
  9. {
  10. public:
  11. bool validPalindrome(string s)
  12. {
  13. int len=s.length();
  14. int left=,right=len-;
  15. while(left<right)
  16. {
  17. if(s[left]!=s[right])
  18. return judgedor(left+,right,s)||judgedor(left,right-,s);
  19. left++;
  20. right--;
  21. }
  22. return true;
  23. }
  24.  
  25. bool judgedor(int l,int r,string &s)
  26. {
  27. while(l<r)
  28. {
  29. if(s[l++]!=s[r--])
  30. return false;
  31. }
  32. return true;
  33. }
  34. };

两端指针,若字符不相等,则跳过左边或者右边继续判定

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. Python 解LeetCode:680. Valid Palindrome II

    题目:给定一个字符串,在最多删除一个字符的情况下,判断这个字符串是不是回文字符串. 思路:回文字符串,第一想到的就是使用两个指针,前后各一个,当遇到前后字符不一致的时候,有两种情况,删除前面字符或者删 ...

随机推荐

  1. PAT1131(dfs)

    In the big cities, the subway systems always look so complex to the visitors. To give you some sense ...

  2. python指针

    class ListNode: def __init__(self, x): self.val = x self.next = None就两个属性 value 和 next,因为单节点默认next是没 ...

  3. stm32中adc的常规通道和注入通道的区别

    STM32的每个ADC模块通过内部的模拟多路开关,可以切换到不同的输入通道并进行转换.STM32特别地加入了多种成组转换的模式,可以由程序设置好之后,对多个模拟通道自动地进行逐个地采样转换. 有2种划 ...

  4. 微信小程序开发——导航失效的解决办法

    异常描述: 使用 navigator 导航,各种属性配置没问题,就是点击死活不跳转. 异常分析: 遇到这种情况,要先考虑的就是当前配置的导航url,是不是已经使用在tabBar中,因为小程序对于nav ...

  5. server2003远程桌面设置一个用户

    开始--程序--管理工具--终端服务配置--限制每个用户使用一个会话

  6. linux修改hosts

    vim /etc/hosts

  7. go语言中的坑

    package main; import ( "fmt" "time" "sync" ) //修改slice的坑 func add(s [] ...

  8. Struts2框架的数据封装一之属性封装(属性封装的第二种方式:封装成javaBean)

    Struts2中提供了两类数据封装的方式? 第一种方式:属性驱动(有两种方式:一个对属性,另外一个是将参数封装到javaBean中) B. 在页面上,使用OGNL表达式进行数据封装.(将参数封装到ja ...

  9. [z]eclipase优化

    eclipse启动优化,终于不那么卡了! 网上找了好多都是myEclipse的优化的,跟eclipse有点区别,找了很多方法还是不能让这个eclipse(Version: Kepler Release ...

  10. 关于EOF:

    请先看下面一段程序: #include"stdio.h" int main() { ],t; int i,j; while(scanf("%s",a)!=EOF ...