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
14 changes: 14 additions & 0 deletions Leetcode Challenge/March/Python/DeleteandEarn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def deleteAndEarn(self, nums: List[int]) -> int:
n = 10001
values=[0]*n
for num in nums:
values[num] += num
take = 0
skip = 0
for i in range(n):
takei = skip + values[i]
skipi = max(skip, take)
take = takei
skip = skipi

return max(take, skip)
43 changes: 43 additions & 0 deletions Strings/KMP Algorithm for Pattern Searching.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
pattern='balu'
text='this is balaji balu'


def lps():
n=len(pattern)
i=1
j=0

while i<n:
if pattern[i]==pattern[j]:
j+=1
lp[i]=j
i+=1
else:
if j!=0:
j=lp[j-1]
else:
lp[i]=j
i+=1
print(lp)

def kmp():
m=len(text)
n=len(pattern)
i=j=0

while i<m:
if text[i]==pattern[j]:
i+=1
j+=1
if j==n:
print('pattern found at the index:',i-j)
j=lp[j-1]
elif i<m and pattern[j]!=text[i]:
if j!=0:
j=lp[j-1]
else:
i+=1
lp=[0]*(len(pattern))
lps()
kmp()