12 2015 档案

摘要:这个题很有意思,看题目可以想到利用循环链表,将链表构成一个环后,旋转一定角度后,然后再拆开环,就可以得到新的链表这里需要注意的就是k值和链表长度的关系,我们可以将环看做钟表,链表长度n就是这个钟表的最大刻度,k值是指针走过的刻度,k值可以比n小,也可以比n大,因为钟表环形循环的特点,指针可能已经绕了... 阅读全文
posted @ 2015-12-28 22:38 sdlwlxf 阅读(121) 评论(0) 推荐(0)
摘要:Given a singly linked listL:L0→L1→…→Ln-1→Ln,reorder it to:L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For exam... 阅读全文
posted @ 2015-12-25 11:25 sdlwlxf 阅读(161) 评论(0) 推荐(0)
摘要:Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should preserve the origi... 阅读全文
posted @ 2015-12-24 18:02 sdlwlxf 阅读(130) 评论(0) 推荐(0)
摘要:本题与之前单链表逆置不同的是,加入了范围判断。依然沿用之前单链表逆置的方法,只需要再做好起始节点和末尾节点的判断说起来容易,做起来复杂,特别是单链表,很容易把人搞晕,所以,在编程之前最后画图理清思路。这次在头结点的处理上,不同于以往设置临时头结点的方法,使用了二级指针,这种方法写出来的代码可能比较少... 阅读全文
posted @ 2015-12-24 17:47 sdlwlxf 阅读(140) 评论(0) 推荐(0)
摘要:这个题一开始本想用快速排序的,但是想了20分钟都没有头绪,难点在于快速排序的随机访问无法用链表实现,不过如果可以实现快速排序partition函数就可以了,但是这可能比较复杂,于是改用其他排序方法,上网查了下,大部分都采用了归并排序,归并排序并不需要有跨度的访问元素,可能唯一耗时的就是寻找中间点,这... 阅读全文
posted @ 2015-12-23 16:47 sdlwlxf 阅读(158) 评论(0) 推荐(0)
摘要:Sort a linked list using insertion sort.这个题我巧妙的设置了一个临时头结点class Solution {public: ListNode* insertionSortList(ListNode* head) { if (head == n... 阅读全文
posted @ 2015-12-22 21:44 sdlwlxf 阅读(144) 评论(0) 推荐(0)
摘要:#ifndef __BINARY_HEAP_H__#define __BINARY_HEAP_H__#include #include #include template class HeapStruct { friend std::ostream& operator(std::ostream... 阅读全文
posted @ 2015-12-22 17:52 sdlwlxf 阅读(218) 评论(0) 推荐(0)
摘要:这是leetcode上的3个题目,要求用非递归实现,其中以后序遍历实现最难,既然递归实现的三种遍历程序只需要改变输入代码顺序,为什么循环不可以呢,带着这种执拗的想法,我开始了这次研究我依然是将递归用栈来实现,而不打算使用改变二叉树结构的方法,那个我打算日后研究首先以前序遍历为例递归实现是:void ... 阅读全文
posted @ 2015-12-17 16:31 sdlwlxf 阅读(3969) 评论(0) 推荐(0)
摘要:Search for a RangeGiven a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity ... 阅读全文
posted @ 2015-12-15 14:12 sdlwlxf 阅读(150) 评论(0) 推荐(0)
摘要:#ifndef __RED_BLACK_TREE_H__#define __RED_BLACK_TREE_H__namespace lxf { template class RedBlackTree { struct Node { enum Colo... 阅读全文
posted @ 2015-12-02 18:23 sdlwlxf 阅读(194) 评论(0) 推荐(0)