摘要:
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.. 阅读全文
摘要:
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.. 阅读全文
摘要:
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 阅读全文
摘要:
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 阅读全文
摘要:
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 阅读全文