08 2015 档案

摘要:Given two stringssandt, write a function to determine iftis an anagram ofs.For example,s= "anagram",t= "nagaram", return true.s= "rat",t= "car", retur... 阅读全文
posted @ 2015-08-09 00:11 ~每天进步一点点~ 阅读(167) 评论(0) 推荐(0)
摘要:Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. Th... 阅读全文
posted @ 2015-08-09 00:00 ~每天进步一点点~ 阅读(209) 评论(0) 推荐(0)
摘要:Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted in asc... 阅读全文
posted @ 2015-08-08 23:36 ~每天进步一点点~ 阅读(247) 评论(0) 推荐(0)
摘要:Given an arraynums, there is a sliding window of sizekwhich is moving from the very left of the array to the very right. You can only see theknumbers ... 阅读全文
posted @ 2015-08-08 20:51 ~每天进步一点点~ 阅读(205) 评论(0) 推荐(0)
摘要:Given an array ofnintegers wheren> 1,nums, return an arrayoutputsuch thatoutput[i]is equal to the product of all the elements ofnumsexceptnums[i].Solv... 阅读全文
posted @ 2015-08-08 20:13 ~每天进步一点点~ 阅读(142) 评论(0) 推荐(0)
摘要:Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is1 -> 2 -> 3 -> ... 阅读全文
posted @ 2015-08-08 19:48 ~每天进步一点点~ 阅读(109) 评论(0) 推荐(0)
摘要:Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to thedefinition of LCA on Wikipedia: “The lowest ... 阅读全文
posted @ 2015-08-08 19:41 ~每天进步一点点~ 阅读(227) 评论(0) 推荐(0)
摘要:Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to thedefinition of LCA on Wikipedia: ... 阅读全文
posted @ 2015-08-08 18:34 ~每天进步一点点~ 阅读(254) 评论(0) 推荐(0)
摘要:Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?/** * Definition for singly-linked l... 阅读全文
posted @ 2015-08-08 18:04 ~每天进步一点点~ 阅读(114) 评论(0) 推荐(0)
摘要:Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example:Given n = 13,Return 6... 阅读全文
posted @ 2015-08-08 17:32 ~每天进步一点点~ 阅读(112) 评论(0) 推荐(1)
摘要:Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front o... 阅读全文
posted @ 2015-08-08 16:55 ~每天进步一点点~ 阅读(119) 评论(0) 推荐(0)
摘要:Given an integer, write a function to determine if it is a power of two.public class Solution { //注意0和负数都返回false!!! /*public boolean isP... 阅读全文
posted @ 2015-08-08 16:38 ~每天进步一点点~ 阅读(191) 评论(0) 推荐(0)
摘要:Given a binary search tree, write a functionkthSmallestto find thekth smallest element in it.Note:You may assume k is always valid, 1 ≤ k ≤ BST's tota... 阅读全文
posted @ 2015-08-08 16:15 ~每天进步一点点~ 阅读(102) 评论(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.public... 阅读全文
posted @ 2015-08-08 15:54 ~每天进步一点点~ 阅读(155) 评论(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"].public cl... 阅读全文
posted @ 2015-08-08 15:16 ~每天进步一点点~ 阅读(127) 评论(0) 推荐(0)
摘要:Implement a basic calculator to evaluate a simple expression string.The expression string contains onlynon-negativeintegers,+,-,*,/operators and empty... 阅读全文
posted @ 2015-08-08 14:54 ~每天进步一点点~ 阅读(491) 评论(0) 推荐(0)
摘要:Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1/** * Definition for a binary tree node... 阅读全文
posted @ 2015-08-08 14:16 ~每天进步一点点~ 阅读(94) 评论(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-08-08 14:04 ~每天进步一点点~ 阅读(131) 评论(0) 推荐(0)
摘要:Implement a basic calculator to evaluate a simple expression string.The expression string may contain open(and closing parentheses), the plus+or minus... 阅读全文
posted @ 2015-08-08 13:17 ~每天进步一点点~ 阅读(217) 评论(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-08-07 23:22 ~每天进步一点点~ 阅读(113) 评论(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-08-07 23:08 ~每天进步一点点~ 阅读(180) 评论(0) 推荐(0)
摘要:Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.For example, given the following matr... 阅读全文
posted @ 2015-08-07 20:12 ~每天进步一点点~ 阅读(149) 评论(0) 推荐(0)
摘要:Given an array of integers and an integerk, find out whether there there are two distinct indicesiandjin the array such thatnums[i] = nums[j]and the d... 阅读全文
posted @ 2015-08-06 23:08 ~每天进步一点点~ 阅读(124) 评论(0) 推荐(0)
摘要:A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose you aregiven... 阅读全文
posted @ 2015-08-06 22:57 ~每天进步一点点~ 阅读(175) 评论(0) 推荐(0)
摘要:Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the arr... 阅读全文
posted @ 2015-08-06 22:12 ~每天进步一点点~ 阅读(109) 评论(0) 推荐(0)
摘要:Find all possible combinations ofknumbers that add up to a numbern, given that only numbers from 1 to 9 can be used and each combination should be a u... 阅读全文
posted @ 2015-08-06 21:17 ~每天进步一点点~ 阅读(127) 评论(0) 推荐(0)
摘要:Find thekth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For exampl... 阅读全文
posted @ 2015-08-06 21:04 ~每天进步一点点~ 阅读(126) 评论(0) 推荐(0)
摘要:Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can f... 阅读全文
posted @ 2015-08-06 20:58 ~每天进步一点点~ 阅读(126) 评论(0) 推荐(0)
摘要:Note:This is an extension ofHouse Robber.After robbing those houses on that street, the thief has found himself a new place for his thievery so that h... 阅读全文
posted @ 2015-08-06 19:58 ~每天进步一点点~ 阅读(129) 评论(0) 推荐(0)
摘要:Given a 2D board and a list of words from the dictionary, find all words in the board.Each word must be constructed from letters of sequentially adjac... 阅读全文
posted @ 2015-08-06 10:42 ~每天进步一点点~ 阅读(112) 评论(0) 推荐(0)
摘要:Design a data structure that supports the following two operations:void addWord(word)bool search(word)search(word) can search a literal word or a regu... 阅读全文
posted @ 2015-08-05 22:24 ~每天进步一点点~ 阅读(251) 评论(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-08-05 21:47 ~每天进步一点点~ 阅读(192) 评论(0) 推荐(0)
摘要:Given an array ofnpositive integers and a positive integers, find the minimal length of a subarray of which the sum ≥s. If there isn't one, return 0 i... 阅读全文
posted @ 2015-08-04 22:36 ~每天进步一点点~ 阅读(108) 评论(0) 推荐(0)
摘要:Trie树又被称为字典树、前缀树,是一种用于快速检索的多叉树。Tried树可以利用字符串的公共前缀来节省存储空间。但如果系统存在大量没有公共前缀的字符串,相应的Trie树将非常消耗内存。(下图为Wiki上的Trie树示意图, https://en.wikipedia.org/wiki/Trie)子节... 阅读全文
posted @ 2015-08-04 22:27 ~每天进步一点点~ 阅读(145) 评论(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-08-04 21:54 ~每天进步一点点~ 阅读(137) 评论(0) 推荐(0)
摘要:Reverse a singly linked list./** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int... 阅读全文
posted @ 2015-08-03 22:38 ~每天进步一点点~ 阅读(149) 评论(0) 推荐(0)
摘要:Given two stringssandt, determine if they are isomorphic.Two strings are isomorphic if the characters inscan be replaced to gett.All occurrences of a ... 阅读全文
posted @ 2015-08-03 22:29 ~每天进步一点点~ 阅读(107) 评论(0) 推荐(0)
摘要:Description:Count the number of prime numbers less than a non-negative number,n.public class Solution { public int countPrimes(int n) { //筛选... 阅读全文
posted @ 2015-08-03 22:14 ~每天进步一点点~ 阅读(92) 评论(0) 推荐(0)
摘要:Remove all elements from a linked list of integers that have valueval.ExampleGiven:1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6,val= 6Return:1 --> 2 --> 3 --... 阅读全文
posted @ 2015-08-03 22:02 ~每天进步一点点~ 阅读(104) 评论(0) 推荐(0)
摘要:Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer... 阅读全文
posted @ 2015-08-03 21:54 ~每天进步一点点~ 阅读(132) 评论(0) 推荐(0)
摘要:Given a range [m, n] where 0 m 1101 11111111 –>n 可以去掉的就是n的分割部分的1。 所以结果其实就是m和n公共头部*/ int res=0; if(m==0)return 0; ... 阅读全文
posted @ 2015-08-03 21:40 ~每天进步一点点~ 阅读(133) 评论(0) 推荐(0)
摘要:Given a 2d grid map of'1's (land) and'0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent ... 阅读全文
posted @ 2015-08-03 21:26 ~每天进步一点点~ 阅读(158) 评论(0) 推荐(0)
摘要:Given a binary tree, imagine yourself standing on therightside of it, return the values of the nodes you can see ordered from top to bottom.For exampl... 阅读全文
posted @ 2015-08-03 20:56 ~每天进步一点点~ 阅读(125) 评论(0) 推荐(0)
摘要:You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping yo... 阅读全文
posted @ 2015-08-03 20:46 ~每天进步一点点~ 阅读(143) 评论(0) 推荐(0)
摘要:Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as theHamming weight).For example, the 32-bit in... 阅读全文
posted @ 2015-08-03 20:34 ~每天进步一点点~ 阅读(85) 评论(0) 推荐(0)
摘要:Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as00000010100101000001111010011100), return ... 阅读全文
posted @ 2015-08-03 20:31 ~每天进步一点点~ 阅读(97) 评论(0) 推荐(0)
摘要:Rotate an array ofnelements to the right byksteps.For example, withn= 7 andk= 3, the array[1,2,3,4,5,6,7]is rotated to[5,6,7,1,2,3,4].Note:Try to come... 阅读全文
posted @ 2015-08-03 19:50 ~每天进步一点点~ 阅读(117) 评论(0) 推荐(0)
摘要:All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to ... 阅读全文
posted @ 2015-08-02 23:33 ~每天进步一点点~ 阅读(128) 评论(0) 推荐(0)
摘要:Given a list of non negative integers, arrange them such that they form the largest number.For example, given[3, 30, 34, 5, 9], the largest formed num... 阅读全文
posted @ 2015-08-02 23:06 ~每天进步一点点~ 阅读(178) 评论(0) 推荐(0)
摘要:The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a... 阅读全文
posted @ 2015-08-02 18:31 ~每天进步一点点~ 阅读(151) 评论(0) 推荐(0)
摘要:Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Callingnext()will return the next... 阅读全文
posted @ 2015-08-02 18:04 ~每天进步一点点~ 阅读(102) 评论(0) 推荐(0)
摘要:Given an integern, return the number of trailing zeroes inn!.Note:Your solution should be in logarithmic time complexity.public class Solution { pu... 阅读全文
posted @ 2015-08-02 17:41 ~每天进步一点点~ 阅读(107) 评论(0) 推荐(0)
摘要:Related to questionExcel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A ... 阅读全文
posted @ 2015-08-02 17:33 ~每天进步一点点~ 阅读(147) 评论(0) 推荐(0)
摘要:Given an array of sizen, find the majority element. The majority element is the element that appears more than⌊ n/2 ⌋times.You may assume that the arr... 阅读全文
posted @ 2015-08-02 17:06 ~每天进步一点点~ 阅读(94) 评论(0) 推荐(0)
摘要:Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 ->... 阅读全文
posted @ 2015-08-02 16:57 ~每天进步一点点~ 阅读(130) 评论(0) 推荐(0)
摘要:Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractional part is repeating,... 阅读全文
posted @ 2015-08-02 16:06 ~每天进步一点点~ 阅读(124) 评论(0) 推荐(0)
摘要:Compare two version numbersversion1andversion2.Ifversion1>version2return 1, ifversion1len2){ for(int i=len2;i0?1:-1; return 0; }} 阅读全文
posted @ 2015-08-02 15:22 ~每天进步一点点~ 阅读(128) 评论(0) 推荐(0)
摘要:Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 ... 阅读全文
posted @ 2015-08-02 12:30 ~每天进步一点点~ 阅读(142) 评论(0) 推荐(0)
摘要:A peak element is an element that is greater than its neighbors.Given an input array wherenum[i] ≠ num[i+1], find a peak element and return its index.... 阅读全文
posted @ 2015-08-02 11:20 ~每天进步一点点~ 阅读(131) 评论(0) 推荐(0)
摘要:Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a... 阅读全文
posted @ 2015-08-01 22:50 ~每天进步一点点~ 阅读(126) 评论(0) 推荐(0)
摘要:Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes... 阅读全文
posted @ 2015-08-01 22:29 ~每天进步一点点~ 阅读(109) 评论(0) 推荐(0)
摘要:Follow upfor "Find Minimum in Rotated Sorted Array":What ifduplicatesare allowed?Would this affect the run-time complexity? How and why?Suppose a sort... 阅读全文
posted @ 2015-08-01 22:17 ~每天进步一点点~ 阅读(203) 评论(0) 推荐(0)
摘要:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7might become4 5 6 7 0 1 2).Find the minimum element.You m... 阅读全文
posted @ 2015-08-01 21:59 ~每天进步一点点~ 阅读(111) 评论(0) 推荐(0)
摘要:Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".Update (2015-02-12):For C prog... 阅读全文
posted @ 2015-08-01 21:38 ~每天进步一点点~ 阅读(132) 评论(0) 推荐(0)
摘要:Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another express... 阅读全文
posted @ 2015-08-01 20:51 ~每天进步一点点~ 阅读(136) 评论(0) 推荐(0)
摘要:Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line./** * Definition for a point. * class Point { * i... 阅读全文
posted @ 2015-08-01 18:37 ~每天进步一点点~ 阅读(161) 评论(0) 推荐(0)
摘要:Sort a linked list inO(nlogn) time using constant space complexity./** * Definition for singly-linked list. * public class ListNode { * int val; *... 阅读全文
posted @ 2015-08-01 17:58 ~每天进步一点点~ 阅读(122) 评论(0) 推荐(0)
摘要:Sort a linked list using insertion sort./** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * L... 阅读全文
posted @ 2015-08-01 17:16 ~每天进步一点点~ 阅读(143) 评论(0) 推荐(0)