From 71a7f08e9d820981c0fb1467fe2d56753cf8f113 Mon Sep 17 00:00:00 2001 From: Sarvar <56576654+sarvar-akbarov@users.noreply.github.com> Date: Tue, 4 Jul 2023 19:08:33 +0500 Subject: [PATCH] Update 037.md --- solutions/037.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/solutions/037.md b/solutions/037.md index d77e21d..2b2545a 100644 --- a/solutions/037.md +++ b/solutions/037.md @@ -128,4 +128,28 @@ class Solution: return count ``` +### O(nm) solution using regular expressions + +We will check every word that inside has any character that not allowed + +#### PHP +class Solution { + + /** + * @param String $allowed + * @param String[] $words + * @return Integer + */ + function countConsistentStrings($allowed, $words) { + $result = 0; + foreach($words as $word) + { + if(!preg_match('/[^' . $allowed . ']/', $word)){ + $result++; + } + } + return $result; + } +} + ***NB***: If you want to get community points please suggest solutions in other languages as merge requests.