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

Commit26cf7ae

Browse files
refactor 234
1 parent4804888 commit26cf7ae

File tree

1 file changed

+20
-0
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+20
-0
lines changed

‎src/main/java/com/fishercoder/solutions/_234.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,24 @@ public boolean isPalindrome(ListNode head) {
8080
}
8181
}
8282

83+
publicstaticclassSolution3 {
84+
/**
85+
* O(n) time
86+
* O(n) space
87+
*/
88+
publicbooleanisPalindrome(ListNodehead) {
89+
List<Integer>list =newArrayList<>();
90+
while (head !=null) {
91+
list.add(head.val);
92+
head =head.next;
93+
}
94+
for (inti =0,j =list.size() -1;i <=j;i++,j--) {
95+
if (list.get(i) !=list.get(j)) {
96+
returnfalse;
97+
}
98+
}
99+
returntrue;
100+
}
101+
}
102+
83103
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp