- LeetCode 최소 하루에 하나는 풀자는 마인드
- 사용언어: JAVA
206. Reverse Linked List
풀이
- 방법:이전/현재/다음으로 구분해서 순서 뒤바꾸기
/**
* 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 curr = head;
while(curr != null){
ListNode next = curr.next;
curr.next = prev;
prev = curr;
curr = next;
}
return prev;
}
}

- 코드 작성하다가 느낀점
- 생각만 잘하면 쉽게 풀림