Skip to content
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
3 changes: 3 additions & 0 deletions distincDifferenceArray.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Solution:
def distinctDifferenceArray(self, nums: List[int]) -> List[int]:
return [len(set(nums[:i])) - len(set(nums[i:])) for i in range(1, len(nums) + 1)]
11 changes: 11 additions & 0 deletions numOfUneqTriplets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Solution:
def unequalTriplets(self, nums: List[int]) -> int:
count = 0

for i in range(len(nums)-2):
for j in range(i+1, len(nums)-1):
for k in range(j+1, len(nums)):
if nums[i] != nums[j] and nums[j] != nums[k] and nums[i] != nums[k]:
count += 1

return count
28 changes: 28 additions & 0 deletions python/expressionMatching.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Solution:
def matches(self, s: str, p: str, i: int, j: int, memory) -> bool:
# Base cases
if i >= len(s) and j >= len(p):
return True
elif j >= len(p):
return False

# Check if we have already computed the result
if memory[i][j] is not None:
return memory[i][j]

matches = i < len(s) and (s[i] == p[j] or p[j] == '.')
isAMatch = None

if j < len(p) - 1 and p[j+1] == "*":
isAMatch = (matches and self.matches(s,p,i+1,j,memory) or self.matches(s,p,i,j+2,memory))
else:
isAMatch = matches and self.matches(s,p,i+1,j+1,memory)

# We register the result in memory
memory[i][j] = isAMatch

return isAMatch

def isMatch(self, s: str, p: str) -> bool:
memory = [[None] * (len(p)) for i in range(len(s)+1)]
return self.matches(s,p,0,0,memory)
19 changes: 19 additions & 0 deletions python/longestSubstring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
visited = {}
startOfSubstring = 0
largestSubstringLen = 0

for idx, c in enumerate(s):
j = visited.get(c,-1)

if j >= startOfSubstring:
startOfSubstring = j + 1
else:
newLargest = idx - startOfSubstring + 1
if newLargest > largestSubstringLen:
largestSubstringLen = newLargest
visited[c] = idx


return largestSubstringLen