From 4449207e2cefbf4249df6e1f13e5d9b6a83b85aa Mon Sep 17 00:00:00 2001 From: afrinc Date: Sun, 1 Oct 2023 11:52:32 +0530 Subject: [PATCH 1/3] Added Regular Expression matching --- Worktech/Hard/RegularExpressionMatching.java | 33 ++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Worktech/Hard/RegularExpressionMatching.java diff --git a/Worktech/Hard/RegularExpressionMatching.java b/Worktech/Hard/RegularExpressionMatching.java new file mode 100644 index 0000000..91e28c4 --- /dev/null +++ b/Worktech/Hard/RegularExpressionMatching.java @@ -0,0 +1,33 @@ +class Solution { + boolean isMatch (String s, String p) { + boolean dp[][] = new boolean[s.length() + 1][p.length() + 1]; + for(int i = 0; i <= s.length(); i++){ + for(int j = 0; j <= p.length(); j++){ + if(j == 0 && j == i) { + dp[i][j] = true; + } + else if(j == 0) { + dp[i][j] = false; + } + else if(i == 0 && p.charAt(j - 1) != '*') { + dp[i][j] = false; + } + else if(i == 0) { + dp[i][j] = dp[i][j - 2]; + } + else { + if(p.charAt(j - 1) == '.' || s.charAt(i - 1) == p.charAt(j - 1)) { + dp[i][j] = dp[i - 1][j - 1]; + } + if(p.charAt(j - 1) == '*'){ + dp[i][j] = dp[i][j - 2]; + boolean match = ((p.charAt(j - 2) == '.' || p.charAt(j - 2) == s.charAt(i - 1)) && dp[i - 1][j]); + dp[i][j] = dp[i][j] || match; + } + } + } + } + return dp[s.length()][p.length()]; + } +} + From b75b59538de2f2212cedcb9b348c3c7780f60153 Mon Sep 17 00:00:00 2001 From: afrinc Date: Sun, 1 Oct 2023 11:57:44 +0530 Subject: [PATCH 2/3] Revert "Added Regular Expression matching" This reverts commit 4449207e2cefbf4249df6e1f13e5d9b6a83b85aa. --- Worktech/Hard/RegularExpressionMatching.java | 33 -------------------- 1 file changed, 33 deletions(-) delete mode 100644 Worktech/Hard/RegularExpressionMatching.java diff --git a/Worktech/Hard/RegularExpressionMatching.java b/Worktech/Hard/RegularExpressionMatching.java deleted file mode 100644 index 91e28c4..0000000 --- a/Worktech/Hard/RegularExpressionMatching.java +++ /dev/null @@ -1,33 +0,0 @@ -class Solution { - boolean isMatch (String s, String p) { - boolean dp[][] = new boolean[s.length() + 1][p.length() + 1]; - for(int i = 0; i <= s.length(); i++){ - for(int j = 0; j <= p.length(); j++){ - if(j == 0 && j == i) { - dp[i][j] = true; - } - else if(j == 0) { - dp[i][j] = false; - } - else if(i == 0 && p.charAt(j - 1) != '*') { - dp[i][j] = false; - } - else if(i == 0) { - dp[i][j] = dp[i][j - 2]; - } - else { - if(p.charAt(j - 1) == '.' || s.charAt(i - 1) == p.charAt(j - 1)) { - dp[i][j] = dp[i - 1][j - 1]; - } - if(p.charAt(j - 1) == '*'){ - dp[i][j] = dp[i][j - 2]; - boolean match = ((p.charAt(j - 2) == '.' || p.charAt(j - 2) == s.charAt(i - 1)) && dp[i - 1][j]); - dp[i][j] = dp[i][j] || match; - } - } - } - } - return dp[s.length()][p.length()]; - } -} - From fbbf85a21788563446d177b6b67977c3083e5f1f Mon Sep 17 00:00:00 2001 From: afrinc Date: Tue, 30 Sep 2025 22:29:15 +0530 Subject: [PATCH 3/3] adding solution of daily probs --- .../RepeatedSubstringPattern.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 LeetCode/Algorithms/Easy/RepeatedSubstringPattern/RepeatedSubstringPattern.java diff --git a/LeetCode/Algorithms/Easy/RepeatedSubstringPattern/RepeatedSubstringPattern.java b/LeetCode/Algorithms/Easy/RepeatedSubstringPattern/RepeatedSubstringPattern.java new file mode 100644 index 0000000..13da8ca --- /dev/null +++ b/LeetCode/Algorithms/Easy/RepeatedSubstringPattern/RepeatedSubstringPattern.java @@ -0,0 +1,24 @@ +class Solution { + public boolean repeatedSubstringPattern(String s) { + int len = s.length(); + + for(int i = len/2; i >=1 ; i--){ + + if(len % i == 0){ // if String can be divisible within half a length or 1 + + int repeats = len/i; + String subString = s.substring(0, i); + + StringBuilder sb = new StringBuilder(); + + for(int j = 0; j < repeats ; j++){ + sb.append(subString); + } + + if(sb.toString().equals(s)) + return true; + } + } + return false; + } +}