Skip to content

Completed Competitive_Coding-3#1174

Open
sarvanibaru wants to merge 1 commit intosuper30admin:masterfrom
sarvanibaru:master
Open

Completed Competitive_Coding-3#1174
sarvanibaru wants to merge 1 commit intosuper30admin:masterfrom
sarvanibaru:master

Conversation

@sarvanibaru
Copy link

No description provided.

@super30admin
Copy link
Owner

Your solution for Pascal's Triangle is correct and efficient. Well done! The code is clean and well-commented. Here are a few suggestions for improvement:

  1. You can avoid the special case for i=0 by initializing the result with the first row and then looping from i=1 to numRows-1. This might make the code slightly more concise.

For example:

List<List<Integer>> result = new ArrayList<>();
if (numRows == 0) return result;
result.add(Arrays.asList(1));
for (int i = 1; i < numRows; i++) {
    List<Integer> prev = result.get(i-1);
    List<Integer> current = new ArrayList<>();
    current.add(1);
    for (int j = 1; j < i; j++) {
        current.add(prev.get(j-1) + prev.get(j));
    }
    current.add(1);
    result.add(current);
}
return result;
  1. Although your current solution is correct, note that the inner loop condition j <= i - 1 is equivalent to j < i. Using j < i might be more intuitive.

  2. Ensure that you only submit the solution for the problem you are solving. The inclusion of the K-diff Pairs solution in the same file is not appropriate for this context.

Overall, your solution is excellent. Keep up the good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants