FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java-algorithm-interview/src/ch08/P13_2.java at main · onlybooks/java-algorithm-interview · GitHub
onlybooks
/
java-algorithm-interview
Public
Notifications
You must be signed in to change notification settings
Fork
27
Star
110
Code
Issues
4
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
java-algorithm-interview
/
src
/
ch08
/
P13_2.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
27 lines (23 loc) · 779 Bytes
Breadcrumbs
java-algorithm-interview
/
src
/
ch08
/
P13_2.java
Copy path
File metadata and controls
27 lines (23 loc) · 779 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
package
ch08
;
import
datatype
.
ListNode
;
import
java
.
util
.
Deque
;
import
java
.
util
.
LinkedList
;
public
class
P13_2
{
public
boolean
isPalindrome
(
ListNode
head
) {
Deque
<
Integer
>
deque
=
new
LinkedList
<>();
// 연결 리스트를 데크에 삽입
ListNode
node
=
head
;
while
(
node
!=
null
) {
deque
.
add
(
node
.
val
);
node
=
node
.
next
;
}
// 데크가 모두 비거나(짝수 개일 때) 1개 이하(홀수 개일 때)가 될 때까지 비교
while
(!
deque
.
isEmpty
() &&
deque
.
size
() >
1
) {
// 데크의 양끝을 추출해 팰린드롬 여부 확인
if
(
deque
.
pollFirst
() !=
deque
.
pollLast
()) {
return
false
;
}
}
return
true
;
}
}
Back
|
FazBrowse Home
|
New Git URL