Skip to content

Commit fa625bd

Browse files
committed
reverse linked list
1 parent 047a415 commit fa625bd

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

leetcode-study

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 047a415438a8373121413e6a52fd11bdca53efbf

leetcode-study-1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 58e2901afafa568cb0f15d5e002c23444e22cf31

reverse-linked-list/eunhwa99.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* public class ListNode {
4+
* int val;
5+
* ListNode next;
6+
* ListNode() {}
7+
* ListNode(int val) { this.val = val; }
8+
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
9+
* }
10+
*/
11+
12+
// 시간 복잡도: O(N)
13+
// 공간복잡도: O(N)
14+
class Solution {
15+
public ListNode reverseList(ListNode head) {
16+
if(head==null) return head;
17+
18+
ListNode pointer = new ListNode(head.val);
19+
20+
ListNode tempPointer;
21+
while(head.next!=null){
22+
tempPointer = new ListNode(head.next.val, pointer);
23+
pointer = tempPointer;
24+
head = head.next;
25+
}
26+
}
27+
return pointer;
28+
}
29+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 32ed2baa8e51b39625f99ea72a780c6edca6e9ee

0 commit comments

Comments
 (0)