Комментарии:
🔥
ОтветитьThis one reversed my brain
ОтветитьI watched this two times. The second time I didn't understand it. 🤣
She is a great teacher. Excellent explanations.
I wanted to revisit recursion and found lecture 15 and 16. Such an epic professor! I was doing the exercise about basketball and got stuck for a while because her function's docstring said: "order doesn't matter", but it does (e.g. 2+1 and 1+2 are counted as 2 different options)! Pointing it out in case it helps someone :)
Ответитьthose are big chalks😮
ОтветитьThank you.
ОтветитьCorrect me if im wrong but if order in this basketball score recursion example doesnt matter, then there are 4 ways to score 4 points: (1,1,1,1), (1,1,2), (1,3) and (2,2). Yet the recursive function of 4 returns 6. If order of scoring would matter then there are 7 ways for getting to 4 points: (1,1,1,1), (1,1,2), (1,2,1), (2,1,1), (2,2), (1,3) and (3,1), and they dont sum up to returned 6 ways.
ОтветитьThis also works for fib example, if for any reason it helps
def fib(n, d = {1:1, 2:1}):
if n in d:
return d[n]
else:
result = fib(n-1) + fib (n-2)
d[n] = result
return result
Think you mam
Ответитьboolean inListOfLists(List<List<Integer>> L, int e) {
// Base case: if the list is empty, return false
if (L.size() == 0) return false;
// Get the first sublist
List<Integer> sublist = L.get(0);
// Check if the element exists in the current sublist
for (int num : sublist) {
if (num == e) return true;
}
// Recursive case: check the rest of the list of lists
return inListOfLists(L.subList(1, L.size()), e);
}