We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7fe3df4 commit 7b59476Copy full SHA for 7b59476
1 file changed
reverse-linked-list/se6816.java
@@ -0,0 +1,22 @@
1
+/**
2
+ 리스트의 길이 -> N
3
+ 시간 복잡도 : O(N)
4
+ 공간 복잡도 : O(1)
5
+*/
6
+class Solution {
7
+ public ListNode reverseList(ListNode head) {
8
+ return createReverseHead(head);
9
+ }
10
+ private ListNode createReverseHead(ListNode head) {
11
+ ListNode resultHead = null;
12
+
13
+ while (head != null) {
14
+ ListNode next = head.next;
15
+ head.next = resultHead;
16
+ resultHead = head;
17
+ head = next;
18
19
20
+ return resultHead;
21
22
+}
0 commit comments