Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9bf7ef2

Browse files
committed
fix:239
1 parent7f17224 commit9bf7ef2

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

‎leetCode-127-Word-Ladder.md‎

Lines changed: 4 additions & 7 deletions
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
publicclassSolution {
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‎

Lines changed: 7 additions & 7 deletions
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[]=newint[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[]=newint[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[]=newint[n- k+1];

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp