仅作自己学习使用
文章目录
- NO.11 盛最多水的容器(中等)
- NO.83 删除有序链表中的重复元素(简单)
- NO.328 奇偶链表(中等)
NO.11 盛最多水的容器(中等)
- 原文链接:https://leetcode.cn/problems/container-with-most-water/
int maxArea(int* height, int heightSize) {int max = 0;int i = 0, j = heightSize-1,volume;while(i<j){volume = (j-i)*(height[j]<height[i]?height[j]:height[i]);if(volume>max) max = volume;height[j]<height[i]?j--:i++; }return max;
}
NO.83 删除有序链表中的重复元素(简单)
- 原文链接:https://leetcode.cn/problems/remove-duplicates-from-sorted-list/description/
struct ListNode* deleteDuplicates(struct ListNode* head) {if(head == NULL) return NULL; struct ListNode *pre = head; struct ListNode *p = head->next;if(p==NULL) return pre; while(p){ if(pre->val == p->val){ pre->next = p->next;free(p);p = pre->next;}else{ pre = p;p = p->next;}}return head;
}
NO.328 奇偶链表(中等)
- 原文链接:https://leetcode.cn/problems/odd-even-linked-list/description/
struct ListNode* oddEvenList(struct ListNode* head) {struct ListNode* p = head; struct ListNode* r,*q; if(p==NULL) return NULL; if(p->next){ r = p->next;q = r;}else{ return head;}while(p->next && q->next) {p->next = q->next;p = p->next;if(p->next){ q->next = p->next;q = q->next;}}q->next = NULL; p->next = r; return head;
}