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 | 29 |
| 30 |
Tags
- map
- 리소스모니터링
- date
- CSS
- NIO
- javascript
- 큐
- List
- spring boot
- Properties
- 힙덤프
- dfs
- Union-find
- Calendar
- union_find
- priority_queue
- Java
- alter
- sql
- GC로그수집
- JPA
- scanner
- string
- 스택
- BFS
- 스프링부트
- math
- set
- deque
- html
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 |