Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions problems/0028.实现strStr.md
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,6 @@ impl Solution {

pub fn str_str(haystack: String, needle: String) -> i32 {
let (haystack_len, needle_len) = (haystack.len(), needle.len());
if haystack_len == 0 { return 0; }
if haystack_len < needle_len { return -1;}
let (haystack, needle) = (haystack.chars().collect::<Vec<char>>(), needle.chars().collect::<Vec<char>>());
let mut next: Vec<usize> = vec![0; haystack_len];
Expand Down Expand Up @@ -1334,9 +1333,6 @@ impl Solution {
next
}
pub fn str_str(haystack: String, needle: String) -> i32 {
if needle.is_empty() {
return 0;
}
if haystack.len() < needle.len() {
return -1;
}
Expand Down
38 changes: 37 additions & 1 deletion problems/0225.用队列实现栈.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public:

Java:

使用两个 Queue 实现
使用两个 Queue 实现方法1
```java
class MyStack {

Expand Down Expand Up @@ -208,6 +208,42 @@ class MyStack {
}

```
使用两个 Queue 实现方法2
```java
class MyStack {
//q1作为主要的队列,其元素排列顺序和出栈顺序相同
Queue<Integer> q1 = new ArrayDeque<>();
//q2仅作为临时放置
Queue<Integer> q2 = new ArrayDeque<>();

public MyStack() {

}
//在加入元素时先将q1中的元素依次出栈压入q2,然后将新加入的元素压入q1,再将q2中的元素依次出栈压入q1
public void push(int x) {
while (q1.size() > 0) {
q2.add(q1.poll());
}
q1.add(x);
while (q2.size() > 0) {
q1.add(q2.poll());
}
}

public int pop() {
return q1.poll();
}

public int top() {
return q1.peek();
}

public boolean empty() {
return q1.isEmpty();
}
}
```

使用两个 Deque 实现
```java
class MyStack {
Expand Down