Leetcode 118 Pascal Triangle
class Solution:
def generate(self, numRows: int) -> List[List[int]]:
res = [[1]]
for i in range(1, numRows):
row = [1] + [res[-1][j-1] + res[-1][j] for j in range(1,i)] + [1]
res.append(row)
return res
Last posted
Total of 3 posts
Leetcode 118 Pascal Triangle
class Solution:
def generate(self, numRows: int) -> List[List[int]]:
res = [[1]]
for i in range(1, numRows):
row = [1] + [res[-1][j-1] + res[-1][j] for j in range(1,i)] + [1]
res.append(row)
return res
ผิด ๆ ต้องอันนี้
res = [[1]]
for i in range (1, numRows):
begin = [1]
end = [1]
last = res[-1]
middle = [last[j-1] + last[j] for j in range(1, len(last))]
row = [1] + middle + [1]
res.append(row)
return res
929. Unique Email Addresses
class Solution:
def numUniqueEmails(self, emails: List[str]) -> int:
unique_emails = set()
for email in emails:
local, domain = email.split('@')
local = local.split('+')[0] # Remove the part after '+'
local = local.replace('.', '') # Remove all '.'
unique_email = f"{local}@{domain}"
unique_emails.add(unique_email)
return len(unique_emails)
Be Civil — "Be curious, not judgemental"
All contents are responsibility of its posters.