FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaArithmetic/src/datastructure/stack/Solution.java at master · sqlcyi2008/JavaArithmetic · GitHub
sqlcyi2008
JavaArithmetic
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaArithmetic
/
src
/
datastructure
/
stack
/
Solution.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
33 lines (27 loc) · 927 Bytes
Breadcrumbs
JavaArithmetic
/
src
/
datastructure
/
stack
/
Solution.java
Copy path
File metadata and controls
33 lines (27 loc) · 927 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package
datastructure
.
stack
;
class
Solution
{
public
boolean
isValid
(
String
s
) {
ArrayStack
<
Character
>
stack
=
new
ArrayStack
<>();
for
(
int
i
=
0
;
i
<
s
.
length
() ;
i
++){
char
c
=
s
.
charAt
(
i
);
if
(
c
==
'('
||
c
==
'['
||
c
==
'{'
)
stack
.
push
(
c
);
else
{
if
(
stack
.
isEmpty
())
return
false
;
char
topChar
=
stack
.
pop
();
if
(
c
==
')'
&&
topChar
!=
'('
)
return
false
;
if
(
c
==
']'
&&
topChar
!=
'['
)
return
false
;
if
(
c
==
'}'
&&
topChar
!=
'{'
)
return
false
;
}
}
return
stack
.
isEmpty
();
}
public
static
void
main
(
String
[]
args
) {
System
.
out
.
println
((
new
Solution
()).
isValid
(
"()[]{}"
));
System
.
out
.
println
((
new
Solution
()).
isValid
(
"([)]"
));
}
}
Back
|
FazBrowse Home
|
New Git URL