Skip to content
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

10 and 315 | Hard questions added #1069

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Python/10_Regular_Expression_Matching.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'''
Link: https://leetcode.com/problems/regular-expression-matching/

10. Regular Expression Matching (Hard)

Given an input string s and a pattern p, implement regular expression matching with support for '.' and '*' where:

'.' Matches any single character.​​​​
'*' Matches zero or more of the preceding element.
The matching should cover the entire input string (not partial).
'''


class Solution:
def isMatch(self, s: str, p: str) -> bool:
if len(re.findall(p,s))==0:
return False
if re.findall(p,s)[0]==s:
return True
else:
return False
19 changes: 19 additions & 0 deletions Python/315_Count_of_Smaller_Numbers_After_Self.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'''
Link: https://leetcode.com/problems/count-of-smaller-numbers-after-self/

315. Count of Smaller Numbers After Self (Hard)

You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smaller elements to the right of nums[i].
'''


class Solution:
def countSmaller(self, nums: List[int]) -> List[int]:
nums = nums[::-1]
out = []
sorted = []
for num in nums:
c = bisect.bisect_left(sorted, num)
out.append(c)
bisect.insort(sorted, num)
return out[::-1]