2014年1月13日
摘要: Reorder List2014.1.13 22:07Given 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 example,Given{1,2,3,4}, reorder it to{1,4,2,3}.Solution1: My solution for this problem is in three steps: 1. cut the list i 阅读全文
posted @ 2014-01-13 22:17 zhuli19901106 阅读(208) 评论(0) 推荐(0) 编辑
摘要: Linked List Cycle II2014.1.13 21:43Given 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?Solution: This problem doesn't only ask you to check if there is a loop in the list, but also to find out where yo 阅读全文
posted @ 2014-01-13 21:45 zhuli19901106 阅读(148) 评论(0) 推荐(0) 编辑
摘要: Linked List Cycle2014.1.13 21:24Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?Solution: The problem indicated that you shouldn't use extra space. And you might be wondering why you should use extra space if you could just use two poin 阅读全文
posted @ 2014-01-13 21:42 zhuli19901106 阅读(257) 评论(0) 推荐(0) 编辑
摘要: Copy List with Random Pointer2014.1.13 20:45A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.Solution: First of all, the problem description indicated that you have to return a deep copy. 阅读全文
posted @ 2014-01-13 20:49 zhuli19901106 阅读(258) 评论(0) 推荐(0) 编辑
摘要: Single Number II2014.1.13 20:25Given an array of integers, every element appearsthreetimes except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?Solution: Still, exclusive OR is a wonderful operator. This.. 阅读全文
posted @ 2014-01-13 20:44 zhuli19901106 阅读(198) 评论(0) 推荐(0) 编辑
摘要: Single Number2014.1.13 20:17Given an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?Solution: Exclusive OR is a wonderful operator. Time complexity is O.. 阅读全文
posted @ 2014-01-13 20:19 zhuli19901106 阅读(115) 评论(0) 推荐(0) 编辑
摘要: Sum Root to Leaf Numbers2014.1.1 19:55Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which represents the number123.Find the total sum of all root-to-leaf numbers.For example, 1 / \ 2 3The root-to-l.. 阅读全文
posted @ 2014-01-13 20:02 zhuli19901106 阅读(149) 评论(0) 推荐(0) 编辑
摘要: Longest Consecutive Sequence2014.1.13 19:00Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given[100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is[1, 2, 3, 4]. Return its length:4.Your algorithm should run in O(n) complex 阅读全文
posted @ 2014-01-13 19:19 zhuli19901106 阅读(221) 评论(0) 推荐(0) 编辑
摘要: Valid Palindrome2014.1.13 18:48Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama"is a palindrome."race a car"isnota palindrome.Note:Have you consider that the string might be em 阅读全文
posted @ 2014-01-13 18:58 zhuli19901106 阅读(153) 评论(0) 推荐(0) 编辑
摘要: Best Time to Buy and Sell Stock III2014.1.13 01:43Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete at mosttwotransactions.Note:You may not engage in multiple transactions at the same time (ie, you mus 阅读全文
posted @ 2014-01-13 01:46 zhuli19901106 阅读(256) 评论(0) 推荐(0) 编辑