From 806a21b93204d2ccf07bfd34fe257d4940235595 Mon Sep 17 00:00:00 2001 From: Jeongwon Na Date: Wed, 6 Aug 2025 18:30:53 +0200 Subject: [PATCH 1/3] valid palindrome solution --- valid-palindrome/njngwn.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 valid-palindrome/njngwn.java diff --git a/valid-palindrome/njngwn.java b/valid-palindrome/njngwn.java new file mode 100644 index 000000000..3c96125cb --- /dev/null +++ b/valid-palindrome/njngwn.java @@ -0,0 +1,22 @@ +class Solution { + public boolean isPalindrome(String s) { + s = s.toLowerCase(); // convert into lowercase letters + s = s.replaceAll("[^a-zA-Z0-9]", ""); // remove non-alphanumeric characters + int start = 0; + int end = s.length()-1; + + while (start < end) { + char startChar = s.charAt(start); + char endChar = s.charAt(end); + + if (startChar != endChar) { + return false; + } + + ++start; + --end; + } + + return true; + } +} \ No newline at end of file From a6f741bc97a33aeeca5b3c9e8a07c1b3773ed980 Mon Sep 17 00:00:00 2001 From: Jeongwon Na Date: Wed, 6 Aug 2025 18:44:28 +0200 Subject: [PATCH 2/3] valid palindrome solution --- valid-palindrome/njngwn.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/valid-palindrome/njngwn.java b/valid-palindrome/njngwn.java index 3c96125cb..549cb504c 100644 --- a/valid-palindrome/njngwn.java +++ b/valid-palindrome/njngwn.java @@ -19,4 +19,4 @@ public boolean isPalindrome(String s) { return true; } -} \ No newline at end of file +} From bd68fd67e4880d164aa569c1d40f99b533c97a85 Mon Sep 17 00:00:00 2001 From: Jeongwon Na Date: Wed, 6 Aug 2025 18:55:03 +0200 Subject: [PATCH 3/3] decode ways solution --- decode-ways/njngwn.java | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 decode-ways/njngwn.java diff --git a/decode-ways/njngwn.java b/decode-ways/njngwn.java new file mode 100644 index 000000000..3ae1c4cda --- /dev/null +++ b/decode-ways/njngwn.java @@ -0,0 +1,33 @@ +// Time Complexity: O(n), n: s.length() +// Space Complexity: O(n), n: s.length() +class Solution { + public int numDecodings(String s) { + if (s.length() == 0) { // edge case + return 0; + } + + int length = s.length()+1; + int[] cntArr = new int[length]; // using dynamic programming + + // check the case i == 0, i == 1 first + cntArr[0] = 1; + if (s.charAt(0) != '0') { + cntArr[1] = 1; + } + + for (int i = 2; i < length; ++i) { + char ch = s.charAt(i-1); + if (ch != '0') { // check for 1-9 + cntArr[i] += cntArr[i-1]; + } + + // check for 10-26 + int num = (s.charAt(i-2)-'0') * 10 + (ch-'0'); + if (num >= 10 && num <= 26) { + cntArr[i] += cntArr[i-2]; + } + } + + return cntArr[length-1]; + } +}