Completed competitive-coding-3#1171
Completed competitive-coding-3#1171shinjaneegupta wants to merge 1 commit intosuper30admin:masterfrom
Conversation
|
Your solution for Pascal's Triangle is correct and efficient. You have correctly identified the time and space complexity. The approach of initializing each row with None and then setting the first and last elements to 1 is good. However, note that the space complexity should be considered as O(numRows^2) for the output, but the auxiliary space (excluding the output) is indeed O(1). One minor improvement: instead of initializing the list with None and then updating, you can directly create a list of ones for the entire row and then update the middle elements. This might be slightly more efficient and clearer. For example: temp = [1] * (i+1)
for j in range(1, i):
temp[j] = ans[i-1][j-1] + ans[i-1][j]Also, note that the problem requires the first numRows of Pascal's triangle. Your solution handles this correctly. However, if numRows is 0, your code would return an empty list, which is correct as per the constraints (numRows>=1). But it's good to be aware of edge cases. Overall, great job! The code is clean and efficient. |
No description provided.