• 문제 링크
Valid Palindrome II - LeetCode
Can you solve this real interview question? Valid Palindrome II - Given a string s, return true if the s can be palindrome after deleting at most one character from it. Example 1: Input: s = "aba" Output: true Example 2: Input: s = "abca" Output: true E
leetcode.com
• 풀이 코드
public class Solution {
public boolean validPalindrome(String s) {
int l = -1, r = s.length();
while (++l < --r) if (s.charAt(l) != s.charAt(r)) return isPalindrome(s, l + 1, r) || isPalindrome(s, l, r - 1);
return true;
}
private boolean isPalindrome(String s, int l, int r) {
while (l < r) if (s.charAt(l++) != s.charAt(r--)) return false;
return true;
}
}'Problem Solving > LeetCode' 카테고리의 다른 글
| [LeetCode] 693. Binary Number with Alternating Bits - Java (0) | 2026.09.24 |
|---|---|
| [LeetCode] 682. Baseball Game - Java (0) | 2026.09.23 |
| [LeetCode] 674. Longest Continuous Increasing Subsequence - Java (0) | 2026.09.21 |
| [LeetCode] 671. Second Minimum Node In a Binary Tree - Java (0) | 2026.09.20 |
| [LeetCode] 661. Image Smoother - Java (0) | 2026.09.19 |
댓글