-
Notifications
You must be signed in to change notification settings - Fork 7
/
Program.cs
35 lines (33 loc) · 797 Bytes
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
namespace PalindromeLinkedList
{
class ListNode
{
public int val;
public ListNode next;
public ListNode(int x) { val = x; }
}
class Program
{
static void Main(string[] args)
{
}
static bool IsPalindrome(ListNode head)
{
ListNode reverse = null, point = head;
while (point != null)
{
reverse = new ListNode(point.val) {next = reverse};
point = point.next;
}
while (head != null)
{
if (head.val != reverse.val)
return false;
head = head.next;
reverse = reverse.next;
}
return true;
}
}
}