摘要: Given 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) complexity.---public class Solution { public in... 阅读全文
posted @ 2013-10-14 09:32 LEDYC 阅读(325) 评论(0) 推荐(0)
摘要: Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if you are able to reach the last index.For example:A =[2,3,1,1,4], returntrue.A =[3,2,1,0,4], returnfalse.-- 阅读全文
posted @ 2013-10-07 10:36 LEDYC 阅读(141) 评论(0) 推荐(0)
摘要: Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array[−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray[4,−1,2,1]has the largest sum =6.click to show more practice.More practice:If you have figured out the O(n) solution, try 阅读全文
posted @ 2013-10-07 10:26 LEDYC 阅读(158) 评论(0) 推荐(0)
摘要: Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.---similar to 105/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = ... 阅读全文
posted @ 2013-10-03 09:33 LEDYC 阅读(164) 评论(0) 推荐(0)
摘要: A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total number of ways to decode it.For example,Given encoded message"12", it cou 阅读全文
posted @ 2013-10-02 08:44 LEDYC 阅读(149) 评论(0) 推荐(0)
摘要: The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integernrepresenting the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.For example, givenn= 2, return[0,1,3,2]. Its gray code s 阅读全文
posted @ 2013-10-02 08:16 LEDYC 阅读(135) 评论(0) 推荐(0)
摘要: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3->3->4->4->5, return1->2->5.Given1->1->1->2->3, return2->3.---/** * Definition for singly-linked list. * public 阅读全文
posted @ 2013-10-02 04:50 LEDYC 阅读(239) 评论(0) 推荐(0)
摘要: Given two wordsword1andword2, find the minimum number of steps required to convertword1toword2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:a) Insert a characterb) Delete a characterc) Replace a character---Idea: DPi->word1, j->word2insert = 1 阅读全文
posted @ 2013-10-01 02:54 LEDYC 阅读(202) 评论(0) 推荐(0)
摘要: Say 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 must sell the stock before you buy again).--- 阅读全文
posted @ 2013-09-26 09:28 LEDYC 阅读(133) 评论(0) 推荐(0)
摘要: Say 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, you may not engage in multiple transactions at 阅读全文
posted @ 2013-09-26 09:22 LEDYC 阅读(132) 评论(0) 推荐(0)
点击右上角即可分享
微信分享提示