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 97dfab3 commit 4f4ad89Copy full SHA for 4f4ad89
reverse-linked-list/kayden.java
@@ -0,0 +1,26 @@
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
+// 시간복잡도: O(N)
12
+// 공간복잡도: O(1)
13
+class Solution {
14
+ public ListNode reverseList(ListNode head) {
15
+
16
+ ListNode prev = null;
17
18
+ while (head != null){
19
+ ListNode curr = new ListNode(head.val, prev);
20
+ prev = curr;
21
+ head = head.next;
22
+ }
23
24
+ return prev;
25
26
+}
0 commit comments