Solved Pascal's Triangle II with Python and DP

🔺 Day 61 of #LeetCode365 Problem: 119. Pascal’s Triangle II Category: Array | Math | Dynamic Programming Today’s problem felt like déjà vu — same triangle 🟰 smaller goals 😅 Instead of building the whole triangle, we just needed that one special row. Efficiency and focus — that’s the Pascal way 💼 💻 Approach: 👉 Start with the first row [1] 👉 Build each subsequent row using the previous one 👉 Each new row = [0] + prev + [0], then sum adjacent pairs 👉 Return only the last row — no extra baggage ✨ result = [[1]] for i in range(rowIndex): temp = [0] + result[-1] + [0] row = [] for j in range(len(result[-1]) + 1): row.append(temp[j] + temp[j + 1]) result.append(row) return result[-1] ⚙️ Complexity: ⏱ O(n²) | 💾 O(n²) 💡 Lesson: Sometimes you don’t need the whole pyramid — just the one row that takes you closer to the top 🔼 #LeetCode #Python #DynamicProgramming #CodingJourney #100DaysOfCode #FunnyCode #DSA

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories