11 2018 档案
摘要:Given a non empty array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runti
阅读全文
摘要:There are n different online courses numbered from 1 to n. Each course has some duration(course length) t and closed on dth day. A course should be ta
阅读全文
摘要:Given an integer, write a function to determine if it is a power of two. Example 1: Input: 1 Output: true Explanation: 20 = 1 Example 2: Input: 16 Out
阅读全文
摘要:Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replaced to get t. All occurrenc
阅读全文
摘要:Given two binary trees, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally ident
阅读全文
摘要:Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product. Example 1: I
阅读全文
摘要:The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, calcul
阅读全文
摘要:Given an input string, reverse the string word by word. Example: Input: "the sky is blue", Output: "blue is sky the". Note: A word is defined as a seq
阅读全文
摘要:Given a positive integer, return its corresponding column title as appear in an Excel sheet. For example: 1 A 2 B 3 C ... 26 Z 27 AA 28 AB ... Example
阅读全文
摘要:Convert a non negative integer to its english words representation. Given input is guaranteed to be less than 231 1. Example 1: Input: 123 Output: "On
阅读全文
摘要:Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? No extra space solution:
阅读全文
摘要:Reverse a singly linked list. Example: Input: 1 2 3 4 5 NULL Output: 5 4 3 2 1 NULL Follow up: A linked list can be reversed either iteratively or rec
阅读全文
摘要:Given a linked list, rotate the list to the right by k places, where k is non negative. Example 1: Input: 1 2 3 4 5 NULL, k = 2 Output: 4 5 1 2 3 NULL
阅读全文
摘要:Given an absolute path for a file (Unix style), simplify it. For example, path = "/home/", = "/home" path = "/a/./b/../../c/", = "/c" path = "/a/../..
阅读全文
摘要:Let's call an array A a mountain if the following properties hold: A.length = 3 There exists some 0 A[i+1] ... A[A.length 1] Given an array that is de
阅读全文
摘要: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
阅读全文
摘要:Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight). Example 1: Input: 11 Out
阅读全文
摘要:Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]). F
阅读全文
摘要:Given a binary tree, return the inorder traversal of its nodes' values. Example: Input: [1,null,2,3] 1 \ 2 / 3 Output: [1,3,2] Follow up: Recursive so
阅读全文
摘要:Example 1: Given the following tree [3,9,20,null,null,15,7]: Return true. Example 2: Given the following tree [1,2,2,3,3,null,null,4,4]: Return false.
阅读全文
摘要:SQL Schema There is a table World + + + + + + | name | continent | area | population | gdp | + + + + + + | Afghanistan | Asia | 652230 | 25500100 | 20
阅读全文
摘要:Given a list of strings words representing an English Dictionary, find the longest word in words that can be built one character at a time by other wo
阅读全文
摘要:Given an array nums and a value val, remove all instances of that value in place and return the new length. Do not allocate extra space for another ar
阅读全文
摘要:Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: "202" Example 2: Input: 7 Output: " 10" Note: The input will
阅读全文
摘要:Given n, how many structurally unique BST's (binary search trees) that store values 1 ... n? Example: Input: 3 Output: 5 Explanation: Given n = 3, the
阅读全文
摘要:Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]). F
阅读全文
摘要: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 the
阅读全文
摘要:Given a non negative integer numRows, generate the first numRows of Pascal's triangle. In Pascal's triangle, each number is the sum of the two numbers
阅读全文
摘要: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: a1 → a2
阅读全文
摘要:You have a total of n coins that you want to form in a staircase shape, where every k th row must have exactly k coins. Given n, find the total number
阅读全文
摘要:We define the Perfect Number is a positive integer that is equal to the sum of all its positive divisors except itself. Now, given an integer n, write
阅读全文
摘要:Given a binary tree, return all root to leaf paths. Note: A leaf is a node with no children. Example: Input: Output: ["1 2 5", "1 3"] Explanation: All
阅读全文
摘要:The set S originally contains numbers from 1 to n. But unfortunately, due to the data error, one of the numbers in the set got duplicated to another n
阅读全文
摘要:You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you cl
阅读全文
摘要:Given a binary tree and a sum, determine if the tree has a root to leaf path such that adding up all the values along the path equals the given sum. N
阅读全文
摘要:Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest l
阅读全文
摘要:Given the root node of a binary search tree (BST) and a value. You need to find the node in the BST that the node's value equals the given value. Retu
阅读全文
摘要:Given a C++ program, remove comments from it. The program source is an array where source[i] is the i th line of the source code. This represents the
阅读全文
摘要:Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1 ... n. Example: Input: 3 Output: [ [1,null,3,2],
阅读全文
摘要:Write a function that takes a string as input and returns the string reversed. Example 1: Input: "hello" Output: "olleh" Example 2: Input: "A man, a p
阅读全文
摘要:Given a singly linked list, determine if it is a palindrome. Example 1: Input: 1 2 Output: false Example 2: Input: 1 2 2 1 Output: true Follow up: Cou
阅读全文
摘要:Given a non negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note that the row index starts from 0. In Pascal's trian
阅读全文
摘要:Given a string containing digits from 2 9 inclusive, return all possible letter combinations that the number could represent. A mapping of digit to le
阅读全文
摘要:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: 1.
阅读全文
摘要:Implement strStr(). Return the index of the first occurrence of needle in haystack, or 1 if needle is not part of haystack. Example 1: Input: haystack
阅读全文
摘要:Alice and Bob have candy bars of different sizes: A[i] is the size of the i th bar of candy that Alice has, and B[j] is the size of the j th bar of ca
阅读全文
摘要:Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "". Exampl
阅读全文
摘要:We have an array A of non negative integers. For every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]] (with i
阅读全文
摘要:Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. For example, two is written as II in Roman numeral, just two one's
阅读全文
摘要:Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 For example, two
阅读全文
摘要:Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. Example 1: Input: [1,3,null,null,2
阅读全文
摘要:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is symmet
阅读全文
摘要:Given an array where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height balanced binary tree is d
阅读全文
摘要:Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are n
阅读全文
摘要:Given two strings s and t , write a function to determine if t is an anagram of s. Example 1: Input: s = "anagram", t = "nagaram" Output: true Example
阅读全文
摘要:You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 ston
阅读全文
摘要:Consider all the leaves of a binary tree. From left to right order, the values of those leaves form a leaf value sequence. For example, in the given t
阅读全文
摘要:You are given a data structure of employee information, which includes the employee's unique id, his importance value and his direct subordinates' id.
阅读全文
摘要:Given a tree, rearrange the tree in in order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and o
阅读全文
摘要:An array is monotonic if it is either monotone increasing or monotone decreasing. An array A is monotone increasing if for all i = A[j]. Return true i
阅读全文
摘要:We are given two sentences A and B. (A sentence is a string of space separated words. Each word consists only of lowercase letters.) A word is uncommo
阅读全文
摘要:Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. For example
阅读全文
摘要:Given a binary tree struct TreeLinkNode { TreeLinkNode left; TreeLinkNode right; TreeLinkNode next; } Populate each next pointer to point to its next
阅读全文
摘要:Given a binary tree struct TreeLinkNode { TreeLinkNode left; TreeLinkNode right; TreeLinkNode next; } Populate each next pointer to point to its next
阅读全文
摘要:Given a binary tree, flatten it to a linked list in place. For example, given the following tree: The flattened tree should look like:
阅读全文
摘要:Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only
阅读全文
摘要:Given a m x n grid filled with non negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.
阅读全文
摘要:A robot is located at the top left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any p
阅读全文
摘要:A robot is located at the top left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any p
阅读全文
摘要:Given a string containing just the characters '(' and ')', find the length of the longest valid (well formed) parentheses substring. Example 1: Input:
阅读全文
摘要:Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. For example,
阅读全文
摘要:Given a sorted linked list, delete all duplicates such that each element appear only once. Example 1: Input: 1 1 2 Output: 1 2 Example 2: Input: 1 1 2
阅读全文
摘要:Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used. Note: All letters in hexadec
阅读全文
摘要: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
阅读全文
摘要:Given two non negative integers num1 and num2 represented as string, return the sum of num1 and num2. Note: 1. The length of both num1 and num2 is 9:
阅读全文
摘要:Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL query to find all customers who never order anything
阅读全文
摘要: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 of qu
阅读全文
摘要:Write a function that takes a string as input and reverse only the vowels of a string. Example 1: Input: "hello" Output: "holle" Example 2: Input: "le
阅读全文
摘要:In a string composed of 'L', 'R', and 'X' characters, like "RXXLRXRXL", a move consists of either replacing one occurrence of "XL" with "LX", or repla
阅读全文
摘要:Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. Example: Input: n = 4, k = 2 Output: [ [2,4], [3,4], [2,3],
阅读全文
摘要:There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every
阅读全文
摘要:Given a complete binary tree, count the number of nodes. Note: Definition of a complete binary tree from Wikipedia: In a complete binary tree every le
阅读全文
摘要:Given a string S of digits, such as S = "123456579", we can split it into a Fibonacci like sequence [123, 456, 579]. Formally, a Fibonacci like sequen
阅读全文
摘要:Additive number is a string whose digits can form additive sequence. A valid additive sequence should contain at least three numbers. Except for the f
阅读全文
摘要:In a given integer array nums, there is always exactly one largest element. Find whether the largest element in the array is at least twice as much as
阅读全文
摘要:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. Note: For the purpose of this problem, w
阅读全文
摘要:Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]). Y
阅读全文
摘要:Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator. Return the quotient after dividi
阅读全文
摘要: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
阅读全文
摘要:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possib
阅读全文
摘要:Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numb
阅读全文
摘要:Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules: 1. Each row must contain the di
阅读全文
摘要:Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value. Your algorithm's runtime com
阅读全文
摘要:Given an unsorted integer array, find the smallest missing positive integer. Example 1: Input: [1,2,0] Output: 3 Example 2: Input: [3,4, 1,1] Output:
阅读全文
摘要:Given n non negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
阅读全文
摘要:Note: This is a companion problem to the System Design problem: Design TinyURL. TinyURL is a URL shortening service where you enter a URL such as http
阅读全文
摘要:Given two non negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string. Example 1: In
阅读全文
摘要:An image is represented by a 2 D array of integers, each integer representing the pixel value of the image (from 0 to 65535). Given a coordinate (sr,
阅读全文
摘要:Given an integer array with no duplicates. A maximum tree building on this array is defined as follow: The root is the maximum number in the array. Th
阅读全文
摘要:Given a string S of '(' and ')' parentheses, we add the minimum number of parentheses ( '(' or ')', and in any positions ) so that the resulting paren
阅读全文