01 2017 档案
摘要:Given a binary tree, find the length of the longest consecutive sequence path. The path refers to any sequence of nodes from some starting node to any
阅读全文
摘要:Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 / \ 2 3 \ 5 All root-to-leaf paths are: ["1->2->5"
阅读全文
摘要:Given a binary tree, flatten it to a linked list in-place. For example,Given 1 / \ 2 5 / \ \ 3 4 6 The flattened tree should look like: 1 \ 2 \ 3 \ 4
阅读全文
摘要:Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definition of LCA on Wikipedia: “The lowes
阅读全文
摘要:Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. According to the definition of LCA on Wikipedia
阅读全文
摘要:Implement int sqrt(int x). Compute and return the square root of x. 小小的一道题竟然做了半天。。。= = 乘法啊加法啊reverse这些一定要考虑到越界的问题。 另外可以使用start + 1 < end的条件,这个时候一般跳出循环
阅读全文
摘要: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 n
阅读全文
摘要:Given an array of strings, group anagrams together. For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return: [ ["ate", "eat","tea"], ["
阅读全文
摘要:Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. Some hints: Could negative integers be palindromes?
阅读全文
摘要:Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except
阅读全文
摘要:Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpo
阅读全文
摘要:Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the leng
阅读全文
摘要:You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contai
阅读全文
摘要:Winter is coming! Your first job during the contest is to design a standard heater with fixed warm radius to warm all the houses. Now, you are given p
阅读全文
摘要:Given a non-empty string s and an abbreviation abbr, return whether the string matches with the given abbreviation. A string such as "word" contains o
阅读全文
摘要:Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0. You may assum
阅读全文
摘要:Design and implement a TwoSum class. It should support the following operations: add and find. add - Add the number to an internal data structure.find
阅读全文
摘要:Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexi
阅读全文
摘要:Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4]. Not
阅读全文
摘要:Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity. 这道题首先要读懂题目。。。一开始连factori
阅读全文
摘要:Write a function to find the longest common prefix string amongst an array of strings. 这道题利用stringbuffer的delete方法 topsolution是用substring的 还可以用Arrays.s
阅读全文
摘要:Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 这道题要考虑反转之后overflow的问题,感觉我的写法很非主流啊。 还是用主流写法又写了一下
阅读全文
摘要:Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using extra space? 这道题很简单也很经典感觉。一开始用hashset做的,但这样就用了extra s
阅读全文
摘要:Given an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you
阅读全文
摘要:Write a function that takes a string as input and reverse only the vowels of a string. Example 1:Given s = "hello", return "holle". Example 2:Given s
阅读全文
摘要:Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters. Please note that the string
阅读全文
摘要:Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction
阅读全文
摘要: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 intege
阅读全文
摘要:Given a string s and a non-empty string p, find all the start indices of p's anagrams in s. Strings consists of lowercase English letters only and the
阅读全文
摘要:Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may a
阅读全文
摘要:Given a non-negative integer represented as a non-empty array of digits, plus one to the integer. You may assume the integer do not contain any leadin
阅读全文
摘要:Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2. Note: 这道题不能用long会越界,所以只能用string直接来append。精髓在于设置一
阅读全文
摘要:Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters. This
阅读全文
摘要:Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the
阅读全文
摘要:Ugly number is a number that only have factors 2, 3and 5. Design an algorithm to find the nth ugly number. The first 10 ugly numbers are 1, 2, 3, 4, 5
阅读全文
摘要:Implement a stack with min() function, which will return the smallest number in the stack. It should support push, pop and min operation all in O(1) c
阅读全文
摘要:Given an array nums of integers and an int k, partition the array (i.e move the elements in "nums") such that: All elements < k are moved to the left
阅读全文
摘要:Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two n
阅读全文
摘要:Given an integer array, find a subarray with sum closest to zero. Return the indexes of the first number and last number. Example Given [-3, 1, 1, -3,
阅读全文
摘要:Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red,
阅读全文

浙公网安备 33010602011771号