From 9675dc55e1409a9491629ddd8478cd2e2f6b14e3 Mon Sep 17 00:00:00 2001 From: hoonji choi Date: Mon, 6 Jul 2026 16:53:19 -0700 Subject: [PATCH] valid-palindrom solution --- valid-palindrome/hoonjichoi1.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 valid-palindrome/hoonjichoi1.java diff --git a/valid-palindrome/hoonjichoi1.java b/valid-palindrome/hoonjichoi1.java new file mode 100644 index 0000000000..be60940a0e --- /dev/null +++ b/valid-palindrome/hoonjichoi1.java @@ -0,0 +1,23 @@ +class Solution { + public boolean isPalindrome(String s) { + + // removing all non-alphanumeric characters and convert them to lower case + String conveted = s.replaceAll("[^a-zA-Z0-9]", "").toLowerCase(); + + // early return of the empty string case + if (conveted.length() == 0) { + return true; + } + + // check the symmetry + int left = 0, right = conveted.length() - 1; + while (left <= right) { + if (conveted.charAt(left) != conveted.charAt(right)) { + return false; + } + left++; + right--; + } + return true; + } +}