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

Commit4f8a8e9

Browse files
author
zhenyu zhang
committed
update 20、119、905 solutions
1 parent762e8a3 commit4f8a8e9

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

‎src/com/hadley/_119.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
packagecom.hadley;
2+
3+
importjava.util.ArrayList;
4+
importjava.util.List;
5+
6+
/*
7+
2020.08.13
8+
119、Pascal's Triangle II
9+
*/
10+
publicclass_119 {
11+
12+
publicList<Integer>getRow(introwIndex) {
13+
14+
returnnewArrayList<>();
15+
}
16+
}

‎src/com/hadley/_905.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
packagecom.hadley;
2+
3+
/*
4+
2020.08.22
5+
905、Sort Array By Parity
6+
*/
7+
8+
publicclass_905 {
9+
publicint[]sortArrayByParity(int[]A) {
10+
int[]result =newint[A.length];
11+
intstartIndex =0;
12+
intendIndex =A.length -1;
13+
for(inti =0;i <A.length;i++){
14+
if(A[i] %2 ==0){
15+
result[startIndex] =A[i];
16+
startIndex ++;
17+
}else{
18+
result[endIndex] =A[i];
19+
endIndex --;
20+
}
21+
}
22+
returnresult;
23+
}
24+
}

‎src/com/hadley/top100/_020.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
packagecom.hadley.top100;
2+
3+
/*
4+
2020.08.13
5+
20、Valid Parentheses
6+
*/
7+
8+
importjava.util.Stack;
9+
10+
publicclass_020 {
11+
publicbooleanisValid(Strings) {
12+
Stack<Character>stack =newStack<>();
13+
for(inti =0;i <s.length();i++){
14+
if(stack.isEmpty()||s.charAt(i) ==40||s.charAt(i) ==91||s.charAt(i) ==123) {
15+
stack.push(s.charAt(i));
16+
continue;
17+
}elseif(s.charAt(i) ==41){
18+
if(stack.peek() ==40){
19+
stack.pop();
20+
}else{
21+
returnfalse;
22+
}
23+
}elseif(s.charAt(i) ==93){
24+
if(stack.peek() ==91){
25+
stack.pop();
26+
}else{
27+
returnfalse;
28+
}
29+
}elseif(s.charAt(i) ==125){
30+
if(stack.peek() ==123){
31+
stack.pop();
32+
}else{
33+
returnfalse;
34+
}
35+
}
36+
37+
38+
}
39+
returnstack.empty();
40+
}
41+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp