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 03adfe9 commit 4dfafeeCopy full SHA for 4dfafee
reverse-linked-list/mintheon.java
@@ -0,0 +1,27 @@
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
+ ListNode prev = null;
16
+ ListNode cur = head;
17
+
18
+ while(cur != null) {
19
+ ListNode nextTemp = cur.next;
20
+ cur.next = prev;
21
+ prev = cur;
22
+ cur = nextTemp;
23
+ }
24
25
+ return prev;
26
27
+}
0 commit comments