Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wwwanlingxiao
LeetCodeAnimation
Commits
5bf978cf
Commit
5bf978cf
authored
Apr 19, 2020
by
JingmingZhang
Browse files
Solved @zjming
parents
Changes
21
Hide whitespace changes
Inline
Side-by-side
0946--validate-stack-sequences/Code/1.java
0 → 100644
View file @
5bf978cf
class
Solution
{
public
boolean
validateStackSequences
(
int
[]
pushed
,
int
[]
popped
)
{
int
N
=
pushed
.
length
;
Stack
<
Integer
>
stack
=
new
Stack
();
int
j
=
0
;
for
(
int
x:
pushed
)
{
stack
.
push
(
x
);
while
(!
stack
.
isEmpty
()
&&
j
<
N
&&
stack
.
peek
()
==
popped
[
j
])
{
//队头元素出队,栈顶元素出栈
stack
.
pop
();
j
++;
}
}
if
(!
stack
.
isEmpty
()){
return
false
;
}
return
true
;
}
}
\ No newline at end of file
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment