250x250
Notice
Recent Posts
Recent Comments
Link
반응형
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- scanner
- NIO
- sql
- deque
- CSS
- 스택
- JPA
- html
- map
- spring boot
- Java
- javascript
- BFS
- date
- string
- union_find
- set
- Union-find
- 리소스모니터링
- 큐
- alter
- Properties
- 스프링부트
- GC로그수집
- dfs
- Calendar
- priority_queue
- 힙덤프
- List
- math
Archives
- Today
- Total
매일 조금씩
Leet code (Easy) : 206. Reverse Linked List - JAVA 본문
728x90
반응형
링크드리스트의 개념을 이해하도록 도와주는 문제였다.
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode reverseList(ListNode head) {
ListNode prev = null;
ListNode next = null;
ListNode curr = head;
while(curr != null){
next = curr.next;
// 다음 노드를 가리키는 방향을 반대로 바꿈
curr.next = prev;
prev = curr;
curr = next;
}
return prev;
}
}
728x90
반응형
'알고리즘 > LinkedList' 카테고리의 다른 글
Leet code (Medium): 143. Reorder List - JAVA (2) | 2024.10.20 |
---|---|
Leet code (Medium): 19. Remove Nth Node From End of List - JAVA (0) | 2024.10.19 |
Leet code (Hard): 23. Merge k Sorted Lists - JAVA (0) | 2024.10.17 |
Leet code (Easy) : 21. Merge Two Sorted Lists - JAVA (0) | 2024.10.16 |
Leet code (Easy) : 141. Linked List Cycle - JAVA (1) | 2024.10.16 |