随笔分类 -  leetcode

摘要:Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.According ... 阅读全文
posted @ 2015-09-11 16:15 丶Blank 阅读(208) 评论(0) 推荐(0)
摘要:Given an array containingndistinct numbers taken from0, 1, 2, ..., n, find the one that is missing from the array.For example,Givennums=[0, 1, 3]retur... 阅读全文
posted @ 2015-09-11 16:09 丶Blank 阅读(167) 评论(0) 推荐(0)
摘要:Given an array of numbersnums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements t... 阅读全文
posted @ 2015-08-18 23:45 丶Blank 阅读(1423) 评论(0) 推荐(0)
摘要:Implement a trie withinsert,search, andstartsWithmethods.Note:You may assume that all inputs are consist of lowercase lettersa-z.实现一个字典树。好久不做题,没感觉啊,Tr... 阅读全文
posted @ 2015-07-27 18:09 丶Blank 阅读(165) 评论(0) 推荐(0)
摘要:There are a total ofncourses you have to take, labeled from0ton - 1.Some courses may have prerequisites, for example to take course 0 you have to firs... 阅读全文
posted @ 2015-07-27 13:32 丶Blank 阅读(200) 评论(0) 推荐(0)
摘要:Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of ... 阅读全文
posted @ 2015-06-30 14:14 丶Blank 阅读(193) 评论(0) 推荐(0)
摘要:Given an integer array of sizen, find all elements that appear more than⌊ n/3 ⌋times. The algorithm should run in linear time and in O(1) space.题目大意:给... 阅读全文
posted @ 2015-06-30 00:34 丶Blank 阅读(253) 评论(0) 推荐(0)
摘要:Given a sorted integer array without duplicates, return the summary of its ranges.For example, given[0,1,2,4,5,7], return["0->2","4->5","7"].题目大意:给一个有... 阅读全文
posted @ 2015-06-29 22:41 丶Blank 阅读(207) 评论(0) 推荐(0)
摘要:Given an array of integers, find out whether there are two distinct indicesiandjin the array such that the difference betweennums[i]andnums[j]is at mo... 阅读全文
posted @ 2015-06-25 15:20 丶Blank 阅读(141) 评论(0) 推荐(0)
摘要:Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space i... 阅读全文
posted @ 2015-06-25 13:41 丶Blank 阅读(158) 评论(0) 推荐(0)
摘要:A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point ... 阅读全文
posted @ 2015-06-25 13:39 丶Blank 阅读(132) 评论(0) 推荐(0)
摘要:Implementint sqrt(int x).Compute and return the square root ofx.题目大意:实现求一个int的根。解题思路:二分。public class Solution { public int mySqrt(int x) { i... 阅读全文
posted @ 2015-06-25 13:36 丶Blank 阅读(169) 评论(0) 推荐(0)
摘要:Given an absolute path for a file (Unix-style), simplify it.For example,path="/home/", =>"/home"path="/a/./b/../../c/", =>"/c"题目大意:给一个String,表示一个文件的绝对... 阅读全文
posted @ 2015-06-25 13:34 丶Blank 阅读(166) 评论(0) 推荐(0)
摘要:Given acompletebinary tree, count the number of nodes.Definition of a complete binary tree fromWikipedia:In a complete binary tree every level, except... 阅读全文
posted @ 2015-06-25 12:33 丶Blank 阅读(175) 评论(0) 推荐(0)
摘要:Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top()... 阅读全文
posted @ 2015-06-25 11:37 丶Blank 阅读(128) 评论(0) 推荐(0)
摘要:Description:Count the number of prime numbers less than a non-negative number,n.题目大意:给一个int,返回小于它的质数的数量。解题思路:打表。public class Solution { public ... 阅读全文
posted @ 2015-06-25 11:34 丶Blank 阅读(170) 评论(0) 推荐(0)
摘要:Find the total area covered by tworectilinearrectangles in a2Dplane.Each rectangle is defined by its bottom left corner and top right corner as shown ... 阅读全文
posted @ 2015-06-25 11:32 丶Blank 阅读(145) 评论(0) 推荐(0)
摘要:Given an array withnobjects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, wh... 阅读全文
posted @ 2015-06-25 11:29 丶Blank 阅读(131) 评论(0) 推荐(0)
摘要:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in or... 阅读全文
posted @ 2015-06-25 11:19 丶Blank 阅读(132) 评论(0) 推荐(0)
摘要:Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Trivia:This problem was inspired bythis... 阅读全文
posted @ 2015-06-25 11:11 丶Blank 阅读(154) 评论(0) 推荐(0)