摘要: 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-06-18 22:50 OpenSoucre 阅读(143) 评论(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-06-18 22:25 OpenSoucre 阅读(131) 评论(0) 推荐(0)
摘要: Given a stringsand a dictionary of wordsdict, determine ifscan be segmented into a space-separated sequence of one or more dictionary words.For exampl... 阅读全文
posted @ 2014-06-18 21:18 OpenSoucre 阅读(171) 评论(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 @ 2014-06-18 19:45 OpenSoucre 阅读(116) 评论(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-06-18 17:15 OpenSoucre 阅读(166) 评论(0) 推荐(0)
摘要: Sort a linked list using insertion sort.单链表的插入排序, 考查的时单链表指针的断开和插入操作#include #include #include using namespace std;struct ListNode{ int val; List... 阅读全文
posted @ 2014-06-18 16:48 OpenSoucre 阅读(123) 评论(0) 推荐(0)
摘要: Sort a linked list inO(nlogn) time using constant space complexity.本题利用归并排序即可归并排序的核心是将两部分合成一部分,故开始要将链表分成两部分,利用快慢两个指针,当快指针跑到链表尾部时,慢指针恰好在中间,故可以将链表分成两部分然... 阅读全文
posted @ 2014-06-18 16:16 OpenSoucre 阅读(165) 评论(0) 推荐(0)
摘要: Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line.此题是求直线上点最多的点数,根据两点构成一条直线,在同一条直线上,任意两点之间的斜率都相同,故需要对每个点... 阅读全文
posted @ 2014-06-18 14:31 OpenSoucre 阅读(152) 评论(0) 推荐(0)
摘要: Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another express... 阅读全文
posted @ 2014-06-18 12:32 OpenSoucre 阅读(144) 评论(0) 推荐(0)
摘要: Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".此题要注意的几个情况是:(1)输入字符串可能含有前缀0和后缀... 阅读全文
posted @ 2014-06-18 11:17 OpenSoucre 阅读(121) 评论(0) 推荐(0)