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

Commitfa01469

Browse files
author
piggy1991
committed
del
1 parent6e8527d commitfa01469

File tree

2 files changed

+31
-41
lines changed

2 files changed

+31
-41
lines changed

‎stack/IsValid.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,37 @@
33
importjava.util.Stack;
44

55
publicclassIsValid {
6+
publicbooleanisValid1(Strings) {
7+
if (s ==null ||s.length() ==0) {
8+
returntrue;
9+
}
10+
11+
Stack<Character>stack =newStack<Character>();
12+
intlen =s.length();
13+
for (inti =0;i <len;i++) {
14+
charc =s.charAt(i);
15+
if (stack.isEmpty()) {
16+
if (c ==']' ||c ==')' ||c =='}') {
17+
returnfalse;
18+
}
19+
stack.push(c);
20+
continue;
21+
}
22+
23+
if (c ==')' &&stack.peek() =='('
24+
||c ==']' &&stack.peek() =='['
25+
||c =='}' &&stack.peek() =='{'
26+
) {
27+
stack.pop();
28+
}elseif (c =='(' ||c =='[' ||c =='{') {
29+
stack.push(c);
30+
}else {
31+
returnfalse;
32+
}
33+
}
34+
35+
returnstack.isEmpty();
36+
}
637
publicbooleanisValid(Strings) {
738
if (s ==null) {
839
returnfalse;

‎string/IsValid.java

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp