Skip to content

Commit 2ef7791

Browse files
authored
week7
1 parent b664c6c commit 2ef7791

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

โ€Žreverse-linked-list/yeonguchoe.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* struct ListNode {
4+
* int val;
5+
* struct ListNode *next;
6+
* };
7+
*/
8+
struct ListNode* reverseList(struct ListNode* head) {
9+
10+
struct ListNode* ptr1 = NULL;
11+
struct ListNode* ptr2 = head;
12+
struct ListNode* ptr3 = NULL;
13+
14+
while (ptr2 != NULL) {
15+
ptr3 = ptr2->next;
16+
ptr2->next = ptr1;
17+
18+
// ์•ž์œผ๋กœ ์ „์ง„
19+
ptr1 = ptr2;
20+
ptr2 = ptr3;
21+
}
22+
return ptr1;
23+
}
24+
// ์‹œ๊ฐ„ ๋ณต์žก๋„: O(๋…ธ๋“œ ๊ฐœ์ˆ˜)
25+
// ๊ณต๊ฐ„ ๋ณต์žก๋„: O(1)

0 commit comments

Comments
ย (0)