---
# System prepended metadata

title: 2330. Valid Palindrome IV
tags: [Leetcode, Two Pointers, Medium]

---

# 2330. Valid Palindrome IV
###### tags: `Leetcode` `Medium` `Two Pointers`
Link: https://leetcode.com/problems/valid-palindrome-iv/description/
## 思路
只要左右不一样的字符pair小于等于2 就是valid
如果s本来就是一个palindrome 也是valid的
## Code
```java=
class Solution {
    public boolean makePalindrome(String s) {
        int l=0, r=s.length()-1;
        int diff = 0;
        while(l<r){
            if(s.charAt(l)!=s.charAt(r)) diff++;
            l++;
            r--;
        }
        return diff<=2;
    }
}
```