반응형
Valid Palindrome - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
Leetcode - Valid Palindrome
설명
Given a string s, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
Example:
Input: s = "A man, a plan, a canal: Panama"
Output: true
Explanation: "amanaplanacanalpanama" is a palindrome.

제한사항
- s consists only of printable ASCII characters.
소스코드
class Solution {
public boolean isPalindrome(String s) {
boolean answer = true;
s = s.replaceAll("[^a-zA-Z0-9]", "").toLowerCase();
char[] chars = s.toCharArray();
for (int i=0; i<chars.length; i++) {
if (chars[i] != chars[chars.length - 1 - i]) {
return false;
}
}
return answer;
}
}

lemondkel - Overview
4-Year Web programmer. lemondkel has 41 repositories available. Follow their code on GitHub.
github.com
팰린드롬 문제2!
반응형