-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
Dahhou ilyas #10058
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dahhou ilyas #10058
Changes from 7 commits
7ed1046
16803af
9c0e073
fe838c6
797e455
d41a906
cff48ee
0bd8348
629bac9
d90ff92
3a0ea7d
aeccbaf
6fac36f
41f3816
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
""" | ||
Author : ilyas dahhou | ||
Date : Oct 7, 2023 | ||
|
||
Task: | ||
Given an input string (s) and a pattern (p), implement wildcard | ||
pattern matching with support for '?' and '*' where: | ||
|
||
'?' matches any single character. | ||
'*' matches any sequence of characters (including the empty sequence). | ||
The matching should cover the entire input string (not partial). | ||
|
||
Implementation notes: | ||
implementation Dynamic Programming up bottom approach. | ||
|
||
Runtime complexity:O(m * n) | ||
|
||
The implementation was tested on the | ||
leetcode: https://leetcode.com/problems/wildcard-matching/ | ||
|
||
|
||
wildcard matching | ||
Dynamic Programming: top -> down. | ||
|
||
""" | ||
import datetime | ||
|
||
|
||
class CustomTimeZone(datetime.tzinfo): | ||
def utcoffset(self, dt): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: As there is no test file in this pull request nor any test function or class in the file Please provide type hint for the parameter: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: As there is no test file in this pull request nor any test function or class in the file Please provide type hint for the parameter: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: As there is no test file in this pull request nor any test function or class in the file Please provide type hint for the parameter: |
||
print(dt) | ||
return datetime.timedelta(hours=1) | ||
|
||
def dst(self, dt): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: As there is no test file in this pull request nor any test function or class in the file Please provide type hint for the parameter: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: As there is no test file in this pull request nor any test function or class in the file Please provide type hint for the parameter: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: As there is no test file in this pull request nor any test function or class in the file Please provide type hint for the parameter: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: As there is no test file in this pull request nor any test function or class in the file Please provide type hint for the parameter: |
||
print(dt) | ||
return datetime.timedelta(0) | ||
|
||
def tzname(self, dt): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: As there is no test file in this pull request nor any test function or class in the file Please provide type hint for the parameter: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: As there is no test file in this pull request nor any test function or class in the file Please provide type hint for the parameter: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: As there is no test file in this pull request nor any test function or class in the file Please provide type hint for the parameter: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: As there is no test file in this pull request nor any test function or class in the file Please provide type hint for the parameter: |
||
print(dt) | ||
return "Custom Time Zone" | ||
|
||
|
||
tz_maroc = CustomTimeZone() | ||
|
||
now_maroc = datetime.datetime.now(tz=tz_maroc) | ||
|
||
|
||
def is_match(string: str, pattern: str) -> bool: | ||
""" | ||
>>> is_match("aa", "a") | ||
False | ||
|
||
>>> is_match("abc", "abc") | ||
True | ||
|
||
>>> is_match("abc", "*c") | ||
True | ||
|
||
>>> is_match("abc", "a*") | ||
True | ||
|
||
>>> is_match("abc", "*a*") | ||
True | ||
|
||
>>> is_match("abc", "?b?") | ||
True | ||
|
||
>>> is_match("abc", "*?") | ||
True | ||
|
||
>>> is_match("abc", "a*d") | ||
False | ||
|
||
>>> is_match("abc", "a*c?") | ||
False | ||
|
||
>>> is_match("", "") | ||
True | ||
|
||
>>> is_match("a", "") | ||
False | ||
|
||
>>> is_match("", "*") | ||
True | ||
|
||
>>> is_match("abc", "*bc") | ||
True | ||
|
||
>>> is_match("abc", "a*bc") | ||
True | ||
""" | ||
m, n = len(string), len(pattern) | ||
dp = [[False] * (n + 1) for _ in range(m + 1)] | ||
|
||
# Base case | ||
dp[0][0] = True | ||
|
||
# Fill in the first row | ||
for j in range(1, n + 1): | ||
if pattern[j - 1] == "*": | ||
dp[0][j] = dp[0][j - 1] | ||
|
||
# Fill in the rest of the DP table | ||
for i in range(1, m + 1): | ||
for j in range(1, n + 1): | ||
if pattern[j - 1] == "?" or string[i - 1] == pattern[j - 1]: | ||
dp[i][j] = dp[i - 1][j - 1] | ||
elif pattern[j - 1] == "*": | ||
dp[i][j] = dp[i - 1][j] or dp[i][j - 1] | ||
|
||
return dp[m][n] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function:
utcoffset
. If the function does not return a value, please provide the type hint as:def function() -> None:
As there is no test file in this pull request nor any test function or class in the file
dynamic_programming/wildcard_matching.py
, please provide doctest for the functionutcoffset
Please provide type hint for the parameter:
dt