Skip to content

Commit 53abbd2

Browse files
committed
Combination Sum, Combination Sum II
1 parent 5c09392 commit 53abbd2

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

336 Palindrome Pairs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,20 @@ def palindromePairs(self, words: List[str]) -> List[List[int]]:
5555
for idx, w in enumerate(words):
5656
cur = root
5757
for i in range(len(w) - 1, -1, -1):
58-
# cur.children[w[i]] # error, pre-forward unable to handle empty str
59-
if self.is_palindrome(w, 0, i + 1): # exclude w[i] rather than include
58+
# cur.children[w[i]] # error, pre-advancing the trie is unable to handle empty str
59+
if self.is_palindrome(w, 0, i + 1):
6060
cur.pali_prefix_idxes.append(idx)
6161

6262
cur = cur.children[w[i]]
6363

64-
cur.pali_prefix_idxes.append(idx)
64+
cur.pali_prefix_idxes.append(idx) # empty str is palindrome
6565
cur.word_idx = idx # word ends
6666

6767
ret = []
6868
for idx, w in enumerate(words):
6969
cur = root
7070
for i in range(len(w)):
71-
# cur.children.get(w[i], None) # error, pre-forward unable to handle empty str
71+
# cur.children.get(w[i], None) # error, pre-advancing the trie is unable to handle empty str
7272
if self.is_palindrome(w, i, len(w)) and cur.word_idx is not None and cur.word_idx != idx:
7373
ret.append([idx, cur.word_idx])
7474

759 Employee Free Time.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def employeeFreeTime(self, schedule: List[List[List[int]]]) -> List[List[int]]:
6060
6161
Similar to meeting rooms II
6262
"""
63-
max_end = min(
63+
cur_max_end = min(
6464
itv[E]
6565
for itvs in schedule
6666
for itv in itvs
@@ -76,10 +76,10 @@ def employeeFreeTime(self, schedule: List[List[List[int]]]) -> List[List[int]]:
7676
while q:
7777
_, i, j = heapq.heappop(q)
7878
itv = schedule[i][j]
79-
if max_end < itv[S]:
80-
ret.append([max_end, itv[S]])
79+
if cur_max_end < itv[S]:
80+
ret.append([cur_max_end, itv[S]])
8181

82-
max_end = max(max_end, itv[E])
82+
cur_max_end = max(cur_max_end, itv[E])
8383

8484
# next
8585
j += 1
@@ -122,7 +122,7 @@ def employeeFreeTime_error(self, schedule: List[List[List[int]]]) -> List[List[i
122122
use index instead
123123
"""
124124
schedules = list(map(iter, schedule))
125-
max_end = min(
125+
cur_max_end = min(
126126
itv[E]
127127
for emp in schedule
128128
for itv in emp
@@ -136,9 +136,9 @@ def employeeFreeTime_error(self, schedule: List[List[List[int]]]) -> List[List[i
136136
ret = []
137137
while q:
138138
_, itv, emp_iter = heapq.heappop(q)
139-
if max_end < itv[S]:
140-
ret.append([max_end, itv[S]])
141-
max_end = max(max_end, itv[E])
139+
if cur_max_end < itv[S]:
140+
ret.append([cur_max_end, itv[S]])
141+
cur_max_end = max(cur_max_end, itv[E])
142142
itv = next(emp_iter, None)
143143
if itv:
144144
heapq.heappush(q, (itv[S], itv, emp_iter))

0 commit comments

Comments
 (0)