struct ListNode* reverseBetween(struct ListNode* head, int left, int right) {
if (head == NULL || head->next == NULL) return head;
if (left <= 0 && right <= 0) return head;
if (left == right) return head;
struct ListNode* new_head = (struct ListNode*)malloc(sizeof(struct ListNode));
new_head->next = head;
struct ListNode* p = new_head;
struct ListNode* r = new_head;
for (int i = 1; i < left; i++) {
p = p->next;
}//p是原始左结点的前一个结点
for (int i = 1; i <= right; i++) {
r = r->next;
}//r是原始右结点
struct ListNode* prev = r->next;//此时prev是原始右结点的下一个结点
struct ListNode* curr = p->next;//此时curr是原始左结点
struct ListNode* l = p->next;//l是原始左结点
for (int i = 0; i <= right - left; i++) {
struct ListNode* temp = curr->next;
curr->next = prev;
prev = curr;
curr = temp;
}//用循环这样弄不用考虑访问空地址
p->next = prev;//原始左结点的前一个结点指向反转的最后一个结点
return new_head->next;
}