From 20ed8de3ff9da4e1e1a056035d2c03078b1b48cb Mon Sep 17 00:00:00 2001 From: 201625010219 <43445842+201625010219@users.noreply.github.com> Date: Wed, 7 Nov 2018 12:02:05 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E7=AE=80=E5=8D=95=E5=8D=95=20add=20li?= =?UTF-8?q?st.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 判断链表是不是回环链表 --- list.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 list.c diff --git a/list.c b/list.c new file mode 100644 index 0000000..50deb53 --- /dev/null +++ b/list.c @@ -0,0 +1,31 @@ +bool isPalindrome(struct ListNode* head) { + struct ListNode *point1, *point2, *point3; + point3 = point2 = head; + point1 = NULL; + long int sum = 0; + int n = 1; + if(head == NULL || head->next == NULL) + return true; + while(point3->next != NULL)//һαȡֵ + { + sum += n*point3->value; + n++; + point3 = point3->next; + point2->next = point1; //һڵÿգΪúһһ + point1 = point2; + point2 = point3; + } + sum += n*point3->value; + point2->next = point1; + n = 1; + while(point2 != NULL)//ڶα + { + sum -= n*point2->value; + n++; + point2 = point2->next; + } + if(sum == 0) + return true; + else + return false; + } \ No newline at end of file