Skip to content

Commit 11f9a6c

Browse files
authored
Merge branch 'neetcode-gh:main' into main
2 parents 01ec551 + ad607dc commit 11f9a6c

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

java/42-Trapping-Rain-Water.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public int trap(int[] heights) {
1414
right[i] = Math.max(heights[i], max);
1515
max = right[i];
1616
}
17-
System.out.println(Arrays.toString(right));
17+
1818
for (int i = 0; i < heights.length; i++) {
1919
c = c + Math.min(left[i], right[i]) - heights[i];
2020
}

python/79-Word-Search.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ def dfs(r, c, i):
2424
path.remove((r, c))
2525
return res
2626

27+
# To prevent TLE,reverse the word if frequency of the first letter is more than the last letter's
28+
count = defaultdict(int, sum(map(Counter, board), Counter()))
29+
if count[word[0]] > count[word[-1]]:
30+
word = word[::-1]
31+
2732
for r in range(ROWS):
2833
for c in range(COLS):
2934
if dfs(r, c, 0):

0 commit comments

Comments
 (0)