会员
周边
新闻
博问
闪存
众包
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
李杨阳
博客园
首页
新随笔
联系
订阅
管理
2016年8月26日
Reorder List
摘要: 开始用递归总是说超时,迫不得已改成这个了。 还是得注意细节 void reorderList(ListNode* head) { if(head == NULL || head->next==NULL || head->next->next==NULL) return; int i=1,j; Lis
阅读全文
posted @ 2016-08-26 12:06 李杨阳
阅读(117)
评论(0)
推荐(0)
2016年7月27日
Remove Duplicates from Sorted List II
摘要: 还是要将各种状态分类好,可以使用状态转移图等图辅助设计。 代码如下: ListNode* deleteDuplicates(ListNode* head) { if(head==NULL) return head; if(head->next == NULL) return head; ListNo
阅读全文
posted @ 2016-07-27 16:06 李杨阳
阅读(128)
评论(0)
推荐(0)
2016年5月17日
Rotate List
摘要: 还是不是很懂这个算法是要干什么……根据他给的实力我先写了这个函数: ListNode* rotateRight(ListNode* head, int k) { if(head == NULL) return head; if(head->next == NULL) return head; Lis
阅读全文
posted @ 2016-05-17 00:30 李杨阳
阅读(126)
评论(0)
推荐(0)
2016年4月20日
Insertion Sort List
摘要: 刚开始想的复杂很多,后来重新思考了一遍,发现是我想太复杂了。 这个是重改后的第一版,发现效率还能继续提升: if(head==NULL || head->next==NULL) return head; ListNode* nh=head; head = head->next; nh->next =
阅读全文
posted @ 2016-04-20 02:17 李杨阳
阅读(128)
评论(0)
推荐(0)
2016年4月17日
Linked List Cycle II
摘要: 仍然使用龟兔赛跑方法,但还需要在这之上根据证明推倒算法: 不难证明:两指针第一次相遇的地方位于“当慢指针进入环时,快环相对于环起始点的位置”的相反位。例如: 假设一开始Fast和Slow从开始位置开始遍历这个链表。 令m = 3,表示经过三步,Slow结点到达环的起始位置,此时Fast在环的第m个位
阅读全文
posted @ 2016-04-17 21:27 李杨阳
阅读(120)
评论(0)
推荐(0)
2016年4月14日
Linked List Cycle
摘要: 我是用龟兔赛跑法解决的,其他人的答案差不多,表述上有差别。有的方法改了链表,我不太赞成使用: bool hasCycle(ListNode *head) { if(head == NULL) return 0; ListNode* p=head; ListNode* q=head; while(p-
阅读全文
posted @ 2016-04-14 22:03 李杨阳
阅读(115)
评论(0)
推荐(0)
Reverse Linked List和Reverse Linked List II
摘要: 当完全逆置链表时,只用配置好标头,并在另写递归函数逆置链表即可并由主函数调用,程序如下: ListNode* reverseList(ListNode* head) { if(head == NULL) return NULL; ListNode* p=head; while(p->next!=NU
阅读全文
posted @ 2016-04-14 15:10 李杨阳
阅读(128)
评论(0)
推荐(0)
2016年4月13日
Add Two Numbers
摘要: 主要还是要把各种情况分类清楚 ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { if(l1 == NULL) return l2; else if (l2 == NULL) return l1; ListNode* p1 = l1; List
阅读全文
posted @ 2016-04-13 16:05 李杨阳
阅读(138)
评论(0)
推荐(0)
2016年4月7日
Odd Even Linked List
摘要: 我的是以奇数判断循环结束,但是不小心覆盖掉了……当初找更快解法的时候找了这个,说是12ms,结果跟我的一样还是20ms,可能有小差异。 class Solution {public: ListNode* oddEvenList(ListNode* head) { if (head==NULL ||
阅读全文
posted @ 2016-04-07 00:09 李杨阳
阅读(115)
评论(0)
推荐(0)
2016年4月5日
Delete Node in a Linked List
摘要: Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is 1 -> 2 -> 3 -
阅读全文
posted @ 2016-04-05 23:17 李杨阳
阅读(129)
评论(0)
推荐(0)
下一页
公告