Skip to content

Commit 9bf7ef2

Browse files
committed
fix:239
1 parent 7f17224 commit 9bf7ef2

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

leetCode-127-Word-Ladder.md

+4-7
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,12 @@ private boolean bfsHelper(Set<String> set1, Set<String> set2, Set<String> wordSe
210210

211211
```C++
212212
public class Solution {
213-
214-
public int ladderLength(String beginWord, String endWord, Set<String> wordList) {
213+
public int ladderLength(String beginWord, String endWord, List<String> wordList) {
214+
if(!wordList.contains(endWord)) return 0;
215215
Set<String> beginSet = new HashSet<String>(), endSet = new HashSet<String>();
216-
217216
int len = 1;
218217
HashSet<String> visited = new HashSet<String>();
219-
218+
HashSet<String> dict = new HashSet<String>(wordList);
220219
beginSet.add(beginWord);
221220
endSet.add(endWord);
222221
while (!beginSet.isEmpty() && !endSet.isEmpty()) {
@@ -240,19 +239,17 @@ public class Solution {
240239
return len + 1;
241240
}
242241

243-
if (!visited.contains(target) && wordList.contains(target)) {
242+
if (!visited.contains(target) && dict.contains(target)) {
244243
temp.add(target);
245244
visited.add(target);
246245
}
247246
chs[i] = old;
248247
}
249248
}
250249
}
251-
252250
beginSet = temp;
253251
len++;
254252
}
255-
256253
return 0;
257254
}
258255
}

leetcode-239-Sliding-Window-Maximum.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public int[] maxSlidingWindow(int[] nums, int k) {
160160

161161
参考 [这里](https://leetcode.com/problems/sliding-window-maximum/discuss/65881/O(n)-solution-in-Java-with-two-simple-pass-in-the-array) ,一种神奇的解法,有点 [238 题](https://leetcode.wang/leetcode-238-Product-of-Array-Except-Self.html) 解法二的影子。
162162

163-
我们把数组 `k` 个一组就行分组
163+
我们把数组 `k` 个一组进行分组
164164

165165
``` java
166166
nums = [1,3,-1,-3,5,3,6,7], and k = 3
@@ -187,13 +187,13 @@ i 到 j 范围内的数字被分割线分成了两部分
187187
int rightMax[] = new int[n];
188188
max = Integer.MIN_VALUE;
189189
for (int i = n - 1; i >= 0; i--) {
190-
if (i % k == 0) {
191-
max = Integer.MIN_VALUE;
192-
}
193190
if (max < nums[i]) {
194191
max = nums[i];
195192
}
196193
rightMax[i] = Math.max(nums[i], max);
194+
if (i % k == 0) {
195+
max = Integer.MIN_VALUE;
196+
}
197197
}
198198
```
199199

@@ -249,13 +249,13 @@ public int[] maxSlidingWindow(int[] nums, int k) {
249249
int rightMax[] = new int[n];
250250
max = Integer.MIN_VALUE;
251251
for (int i = n - 1; i >= 0; i--) {
252-
if (i % k == 0) {
253-
max = Integer.MIN_VALUE;
254-
}
255252
if (max < nums[i]) {
256253
max = nums[i];
257254
}
258255
rightMax[i] = Math.max(nums[i], max);
256+
if (i % k == 0) {
257+
max = Integer.MIN_VALUE;
258+
}
259259
}
260260

261261
int result[] = new int[n - k + 1];

0 commit comments

Comments
 (0)