Skip to content

Commit 761b685

Browse files
author
Partho Biswas
committed
no message
1 parent 62a37b8 commit 761b685

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,7 @@ Learn the following modules by heart. Just knowing all of the following items wi
11911191
08. **[Dynamic Programming Patterns - MUST READ](https://tinyurl.com/tenzf8b)**
11921192
09. **[My experience and notes for learning DP](https://tinyurl.com/rjg4vtg)**
11931193
10. **[DP IS EASY! 5 Steps to Think Through DP Questions](https://tinyurl.com/vmmaxbe)**
1194+
11. **[Dynamic Programming Patterns](https://tinyurl.com/tenzf8b)**
11941195

11951196
</p>
11961197
</details>

leetcode.com/python/375_Guess_Number_Higher_or_Lower_II.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@ def dfs(self, start, end, record):
77
return start
88

99
if record[start][end] is None:
10-
record[start][end] = min(
11-
(i + max(self.dfs(start, i - 1, record), self.dfs(i + 1, end, record))) for i in range(start, end + 1)
12-
)
10+
pays = []
11+
for i in range(start, end + 1):
12+
prevPay = self.dfs(start, i - 1, record)
13+
nextPay = self.dfs(i + 1, end, record)
14+
currPay = i
15+
totlPay = currPay + max(prevPay, nextPay)
16+
pays.append(totlPay)
17+
18+
record[start][end] = min(pays)
1319

1420
return record[start][end]
1521

0 commit comments

Comments
 (0)