摘要: Sort a linked list inO(nlogn) time using constant space complexity. 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int ... 阅读全文
posted @ 2014-09-13 19:47 yqc 阅读(157) 评论(0) 推荐(0) 编辑
摘要: Sort a linked list using insertion sort. 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *nex... 阅读全文
posted @ 2014-09-13 19:46 yqc 阅读(129) 评论(0) 推荐(0) 编辑
摘要: Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get the valu... 阅读全文
posted @ 2014-09-13 19:45 yqc 阅读(116) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, return thepostordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[3,2,1].No... 阅读全文
posted @ 2014-09-13 19:44 yqc 阅读(107) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, return thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,2,3].Not... 阅读全文
posted @ 2014-09-13 19:43 yqc 阅读(102) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space? 1 /** 2 * Definition for singly-linked l... 阅读全文
posted @ 2014-09-13 19:42 yqc 阅读(86) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up:Can you solve it without using extra space? 1 ... 阅读全文
posted @ 2014-09-13 19:41 yqc 阅读(89) 评论(0) 推荐(0) 编辑
摘要: Given an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity... 阅读全文
posted @ 2014-09-13 19:40 yqc 阅读(113) 评论(0) 推荐(0) 编辑
摘要: Given an array of integers, every element appearsthreetimes except for one. Find that single one.Note:Your algorithm should have a linear runtime comp... 阅读全文
posted @ 2014-09-13 19:39 yqc 阅读(98) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest le... 阅读全文
posted @ 2014-09-13 19:38 yqc 阅读(77) 评论(0) 推荐(0) 编辑