上一页 1 ··· 35 36 37 38 39 40 41 42 43 ··· 51 下一页
2014年1月13日
摘要: 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) 编辑
2014年1月10日
摘要: Best Time to Buy and Sell Stock II2014.1.10 22:39Say 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 as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However 阅读全文
posted @ 2014-01-10 22:50 zhuli19901106 阅读(188) 评论(0) 推荐(0) 编辑
2014年1月9日
摘要: Best Time to Buy and Sell Stock2014.23.56Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.Solution: To maxi. 阅读全文
posted @ 2014-01-09 23:59 zhuli19901106 阅读(153) 评论(0) 推荐(0) 编辑
摘要: Triangle2014.1.9 22:56Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,5,7], [4,1,8,3]]The minimum path sum from top to bottom is11(i.e.,2+3+5+1= 11).Note:Bo... 阅读全文
posted @ 2014-01-09 23:18 zhuli19901106 阅读(207) 评论(0) 推荐(0) 编辑
2014年1月8日
摘要: Pascal's Triangle II2014.1.8 22:58Given an indexk, return thekthrow of the Pascal's triangle.For example, givenk= 3,Return[1,3,3,1].Note:Could you optimize your algorithm to use onlyO(k) extra space?Solution1: Pascal's Triangle is a typical O(n^2) dynamic programming problem. Here is the 阅读全文
posted @ 2014-01-08 23:01 zhuli19901106 阅读(222) 评论(0) 推荐(0) 编辑
摘要: Pascal's Triangle2014.1.8 22:44GivennumRows, generate the firstnumRowsof Pascal's triangle.For example, givennumRows= 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]Solution: Pascal's Triangle is a typical O(n^2) dynamic programming problem. Here is the recurrence relation: 1. f.. 阅读全文
posted @ 2014-01-08 22:49 zhuli19901106 阅读(156) 评论(0) 推荐(0) 编辑
上一页 1 ··· 35 36 37 38 39 40 41 42 43 ··· 51 下一页