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 80151b3 commit 019027cCopy full SHA for 019027c
reverse-linked-list/Tessa1217.java
@@ -0,0 +1,36 @@
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
+ * 링크드 리스트 head가 주어질 때 뒤집은 리스트를 반환하세요.
13
14
+class Solution {
15
+ public ListNode reverseList(ListNode head) {
16
+
17
+ if (head == null) {
18
+ return head;
19
+ }
20
21
+ ListNode prev = head;
22
+ ListNode next = prev.next;
23
+ head.next = null;
24
25
+ while (next != null) {
26
+ ListNode temp = next.next;
27
+ next.next = prev;
28
+ prev = next;
29
+ next = temp;
30
31
32
+ return prev;
33
34
35
+}
36
0 commit comments