# 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; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up