登录
  • #刷题
  • #leetcode

求助,leetcode总是要我在成员申明后面加分号。

tobias0705
1119
2
不明白这样的运行结果:

leetcode的运行结果:Line 12: expected ';' at end of member declaration。



/**[br][/br][br][/br] * Definition for singly-linked list.[br][/br][br][/br] * struct ListNode {[br][/br][br][/br] *     int val;[br][/br][br][/br] *     ListNode *next;[br][/br][br][/br] *     ListNode(int x) : val(x), next(NULL) {}[br][/br][br][/br] * };[br][/br][br][/br] */[br][/br][br][/br] [br][/br][br][/br]class Solution {[br][/br][br][/br]public:[br][/br][br][/br]    ListNode* findMid(LstNode *head);[br][/br][br][/br]    ListNode* reverse(ListNode *head);[br][/br][br][/br]	ListNode* merge(ListNode *head1, ListNode *head2);[br][/br][br][/br]	[br][/br][br][/br]    void reorderList(ListNode *head); [br][/br][br][/br]};[br][/br][br][/br]ListNode* Solution::findMid(ListNode *head){[br][/br][br][/br]	ListNode *fast = head, ListNode *slow = head;[br][/br][br][/br]	if (head == NULL || head->next == NULL) return head;[br][/br][br][/br]	while (fast->next->next != NULL && fast != NULL) [br][/br][br][/br]	{[br][/br][br][/br]		fast = fast->next->next;[br][/br][br][/br]		slow = slow->next;[br][/br][br][/br]	}[br][/br][br][/br]	return slow;[br][/br][br][/br]}[br][/br][br][/br]	[br][/br][br][/br]ListNode* Solution::reverse(ListNode *head){[br][/br][br][/br]	if (head == NULL || head->next == NULL) return head;[br][/br][br][/br]		[br][/br][br][/br]	ListNode *curNode = head, *nextNode;[br][/br][br][/br]	while (curNode->next != NULL)[br][/br][br][/br]	{[br][/br][br][/br]		nextNode = curNode->next;[br][/br][br][/br]		curNode->next = nextNode->next;[br][/br][br][/br]		nextNode->next = head;[br][/br][br][/br]		head = nextNode;[br][/br][br][/br]	}[br][/br][br][/br]	return head;[br][/br][br][/br]}[br][/br][br][/br]	[br][/br][br][/br]ListNode* Solution::merge(ListNode *head1, ListNode *head2){[br][/br][br][/br]	ListNode *tmp, *cur1 = head1, *cur2 = head2;[br][/br][br][/br]		[br][/br][br][/br]	while (cur2 != NULL)[br][/br][br][/br]	{[br][/br][br][/br]		tmp = cur2;[br][/br][br][/br]		cur2 = cur2->next;[br][/br][br][/br]		tmp->next = cur1->next;[br][/br][br][/br]		cur1->next = tmp;[br][/br][br][/br]		cur1 = tmp->next;[br][/br][br][/br]	}[br][/br][br][/br]}[br][/br][br][/br]	[br][/br][br][/br]void Solution::reorderList(ListNode *head) {[br][/br][br][/br]    ListNode *head2 = findMid(head), *head1 = head;[br][/br][br][/br]        [br][/br][br][/br]	head2 = reverse(head2);[br][/br][br][/br]	head1 = merge(head1, head2);[br][/br][br][/br]	head = head1;[br][/br][br][/br]}
2条回复
热度排序

发表回复