Skip to content

Commit 68e3335

Browse files
committed
2020.02.26
1 parent 67af754 commit 68e3335

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

LeetCode206.c

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*************************************************************************
2+
> File Name: LeetCode206.c
3+
> Author: ws
4+
5+
> Created Time: 2020年02月26日 星期三 17时25分19秒
6+
************************************************************************/
7+
8+
struct ListNoderever(struct ListNode *head) {
9+
struct ListNode ret, *p = head, *q;
10+
ret.next = NULL;
11+
while (p) {
12+
q = p->next;
13+
p->next = ret.next;
14+
ret.next = p;
15+
p = q;
16+
}
17+
return ret.next;
18+
}
19+
20+

LeetCode234.c

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*************************************************************************
2+
> File Name: LeetCode234.c
3+
> Author: ws
4+
5+
> Created Time: 2020年02月26日 星期三 17时28分45秒
6+
************************************************************************/
7+
8+
9+
int get_length(struct ListNode *head) {
10+
int n = 0;
11+
while (head) n += 1, head = head->next;
12+
return n;
13+
}
14+
15+
struct ListNode *get_node(struct ListNode *head, int ind) {
16+
while (ind--) head = head->next;
17+
return head;
18+
}
19+
20+
struct ListNode *reverse(struct ListNode *head) {
21+
struct ListNode ret, *p = head, *q;
22+
ret.next = NULL;
23+
while (p) {
24+
q = p->next;
25+
p->next = ret.next;
26+
ret.next = p;
27+
p = q;
28+
}
29+
return ret.next;
30+
}
31+
32+
bool isPalindrome(struct ListNode *head) {
33+
int len = get_length(head);
34+
struct ListNode *p = head, *q = reverse(get_node(head, (len + 1) / 2));
35+
while (q) {
36+
if (p->val - q->val) return false;
37+
p = p->next;
38+
q = q->next;
39+
}
40+
return true;
41+
}
42+

0 commit comments

Comments
 (0)