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

Competitive coding 3 complete #928

Open
wants to merge 1 commit into
base: master
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
35 changes: 35 additions & 0 deletions Problem1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 532. K-diff Pairs in an Array
class Solution:
def findPairs(self, nums: List[int], k: int) -> int:
Map = {}
count = 0

for n in nums:
if n not in Map:
Map[n] = 1
else:
Map[n] += 1
print(Map)

if k == 0:
for n in nums:
if n in Map:
if Map[n] > 1:
count += 1
Map[n] = 0
return count


for n in nums:
value = n-k
if value in Map:
count += 1
Map.pop(value)
else:
count += 0

return count




30 changes: 30 additions & 0 deletions Problem2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 118. Pascal's Triangle
class Solution:
def generate(self, numRows: int) -> List[List[int]]:
output = []
def getRow(r,c):
result = [1]
ans = 1

for i in range(1,r+1):
ans = ans * ((r+1)-i) // i
result.append(ans)
return result

for i in range(numRows):
output.append(getRow(i,i+1))

return output