11 2018 档案
发表于 2018-11-30 22:34阅读:296评论:0推荐:0
摘要:Given an array nums, we call (i, j) an important reverse pair if i < j and nums[i] > 2*nums[j]. You need to return the number of important reverse pai
阅读全文 »
发表于 2018-11-29 22:34阅读:438评论:0推荐:0
摘要:Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen so far as a list of disjoint intervals. For exampl
阅读全文 »
发表于 2018-11-29 21:13阅读:285评论:0推荐:0
摘要:Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Range sum S(i, j) is defined as the sum of the eleme
阅读全文 »
发表于 2018-11-28 22:04阅读:355评论:0推荐:0
摘要:Motivation: Given a 1D array of n elements. [2, 5, -1, 3, 6] range sum query: what's the sum from 2nd element to 4th element query(2, 4)? 5 + (-1) + 3
阅读全文 »
发表于 2018-11-28 21:18阅读:238评论:0推荐:0
摘要:You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smal
阅读全文 »
发表于 2018-11-27 15:26阅读:178评论:0推荐:0
摘要: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
阅读全文 »
发表于 2018-11-27 13:09阅读:176评论:0推荐:0
摘要:Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as: a binary tree in which the dep
阅读全文 »
发表于 2018-11-26 22:11阅读:192评论:0推荐:0
摘要:Given an array of integers, find out whether there are two distinct indices i and j in the array such that the absolute difference between nums[i] and
阅读全文 »
发表于 2018-11-25 12:44阅读:362评论:0推荐:0
摘要:945. Minimum Increment to Make Array Unique Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1. Return the l
阅读全文 »
发表于 2018-11-24 22:30阅读:191评论:0推荐:0
摘要: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
阅读全文 »
发表于 2018-11-24 22:11阅读:294评论:0推荐:0
摘要:Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element.
阅读全文 »
发表于 2018-11-24 18:31阅读:181评论:0推荐:0
摘要:Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of th
阅读全文 »
发表于 2018-11-24 12:22阅读:217评论:0推荐:0
摘要:Given the root node of a binary search tree (BST) and a value to be inserted into the tree, insert the value into the BST. Return the root node of the
阅读全文 »
发表于 2018-11-24 11:40阅读:193评论:0推荐:0
摘要: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
阅读全文 »
发表于 2018-11-24 10:51阅读:228评论:0推荐:0
摘要:Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST. Calling next() will return the n
阅读全文 »
发表于 2018-11-24 09:58阅读:220评论:0推荐:0
摘要: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
阅读全文 »
发表于 2018-11-23 20:45阅读:306评论:0推荐:0
摘要:Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or
阅读全文 »
发表于 2018-11-23 15:50阅读:173评论:0推荐:0
摘要: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
阅读全文 »
发表于 2018-11-22 22:40阅读:248评论:0推荐:0
摘要:Given a binary tree Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL
阅读全文 »
发表于 2018-11-22 22:28阅读:263评论:0推荐:0
摘要:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } Populate each next pointer to point to its ne
阅读全文 »
发表于 2018-11-22 19:08阅读:175评论:0推荐:0
摘要: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,
阅读全文 »
发表于 2018-11-22 18:04阅读:197评论: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. For example,
阅读全文 »
发表于 2018-11-21 22:09阅读:201评论:0推荐:0
摘要: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
阅读全文 »
发表于 2018-11-21 18:33阅读:189评论:0推荐:0
摘要: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
阅读全文 »
发表于 2018-11-21 18:11阅读:291评论:0推荐:0
摘要:"Top-down" Solution Here is the pseudocode for the recursion function maximum_depth(root, depth): 1. return if root is null 2. if root is a leaf node:
阅读全文 »
发表于 2018-11-20 19:48阅读:258评论:0推荐:0
摘要:You have k lists of sorted integers in ascending order. Find the smallest range that includes at least one number from each of the k lists. We define
阅读全文 »
发表于 2018-11-20 15:54阅读:252评论:0推荐:0
摘要:Given a list of directory info including directory path, and all the files with contents in this directory, you need to find out all the groups of dup
阅读全文 »
发表于 2018-11-19 21:47阅读:222评论:0推荐:0
摘要:Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings. You need to h
阅读全文 »
发表于 2018-11-19 20:48阅读:179评论:0推荐:0
摘要:We define a harmonious array is an array where the difference between its maximum value and its minimum value is exactly1. Now, given an integer array
阅读全文 »
发表于 2018-11-19 18:19阅读:196评论:0推荐:0
摘要:Given an integer array with even length, where different numbers in this array represent different kinds of candies. Each number means one candy of th
阅读全文 »
发表于 2018-11-19 18:00阅读:193评论:0推荐:0
摘要:There is a brick wall in front of you. The wall is rectangular and has several rows of bricks. The bricks have the same height but different width. Yo
阅读全文 »
发表于 2018-11-19 12:16阅读:285评论:0推荐:0
摘要:TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/design-tinyurl and it returns a short URL such as http
阅读全文 »
发表于 2018-11-19 10:41阅读:213评论:0推荐:0
摘要:Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1. Example 1: Example 2: Note: The length of the giv
阅读全文 »
发表于 2018-11-19 09:11阅读:193评论:0推荐:0
摘要:Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below. Examp
阅读全文 »
发表于 2018-11-19 08:09阅读:199评论:0推荐:0
摘要:You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/ve
阅读全文 »
发表于 2018-11-18 21:48阅读:278评论:0推荐:0
摘要:Given an array A of strings, find any smallest string that contains each string in A as a substring. We may assume that no string in A is substring of
阅读全文 »
发表于 2018-11-18 20:51阅读:238评论:0推荐:0
摘要:Given a string S that only contains "I" (increase) or "D" (decrease), let N = S.length. Return any permutation A of [0, 1, ..., N] such that for all i
阅读全文 »
发表于 2018-11-18 18:20阅读:225评论:0推荐:0
摘要:Preorder: Approach #1: Recurisive. Approach #2: Iteratively.[Java] Approach #3: Morris Traversal.[C++] Using Morris Traversal can don't use recurisive
阅读全文 »
发表于 2018-11-18 12:30阅读:280评论:0推荐:0
摘要:We are given an array A of N lowercase letter strings, all of the same length. Now, we may choose any set of deletion indices, and for each string, we
阅读全文 »
发表于 2018-11-18 12:29阅读:174评论:0推荐:0
摘要:Given an array A of integers, return true if and only if it is a valid mountain array. Recall that A is a mountain array if and only if: A.length >= 3
阅读全文 »
发表于 2018-11-17 16:36阅读:236评论:0推荐:0
摘要:We are given non-negative integers nums[i] which are written on a chalkboard. Alice and Bob take turns erasing exactly one number from the chalkboard,
阅读全文 »
发表于 2018-11-17 15:49阅读:245评论:0推荐:0
摘要:There are two types of soup: type A and type B. Initially we have N ml of each type of soup. There are four kinds of operations: When we serve some so
阅读全文 »
发表于 2018-11-17 12:09阅读:206评论:0推荐:0
摘要:Sometimes people repeat letters to represent extra feeling, such as "hello" -> "heeellooo", "hi" -> "hiiii". Here, we have groups, of adjacent letters
阅读全文 »
发表于 2018-11-17 12:04阅读:164评论:0推荐:0
摘要:A website domain like "discuss.leetcode.com" consists of various subdomains. At the top level, we have "com", at the next level, we have "leetcode.com
阅读全文 »
发表于 2018-11-16 22:36阅读:249评论:0推荐:0
摘要:Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Example 2: Example 3: Approach #1: c++.
阅读全文 »
发表于 2018-11-16 22:25阅读:273评论:0推荐:0
摘要:Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of points (i, j, k) such that the distance between i and j equals
阅读全文 »
发表于 2018-11-16 19:09阅读:250评论:0推荐:0
摘要: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
阅读全文 »
发表于 2018-11-16 15:49阅读:184评论:0推荐:0
摘要: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
阅读全文 »
发表于 2018-11-16 15:03阅读:173评论:0推荐:0
摘要:Given two strings s and t which consist of only lowercase letters. String t is generated by random shuffling string s and then add one more letter at
阅读全文 »
发表于 2018-11-15 22:33阅读:214评论:0推荐:0
摘要:Design a data structure that supports all following operations in average O(1) time. Note: Duplicate elements are allowed. Example: Approach #1: C++.
阅读全文 »
发表于 2018-11-15 21:44阅读:240评论:0推荐:0
摘要:Design a data structure that supports all following operations in average O(1) time. insert(val): Inserts an item val to the set if not already presen
阅读全文 »
发表于 2018-11-15 21:03阅读:188评论:0推荐:0
摘要:Design a simplified version of Twitter where users can post tweets, follow/unfollow another user and is able to see the 10 most recent tweets in the u
阅读全文 »
发表于 2018-11-15 15:13阅读:250评论:0推荐:0
摘要:Given a non-empty array of integers, return the k most frequent elements. Example 1: Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] Example 2: Input
阅读全文 »
发表于 2018-11-15 14:37阅读:248评论: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
阅读全文 »
发表于 2018-11-14 22:39阅读:222评论:0推荐:0
摘要:Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the
阅读全文 »
发表于 2018-11-14 21:56阅读:252评论:0推荐:0
摘要: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
阅读全文 »
发表于 2018-11-14 21:23阅读:250评论:0推荐:0
摘要:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy
阅读全文 »
发表于 2018-11-14 19:53阅读:291评论: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 intege
阅读全文 »
发表于 2018-11-14 16:39阅读:197评论:0推荐:0
摘要:Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a lette
阅读全文 »
发表于 2018-11-13 22:31阅读:184评论:0推荐:0
摘要:Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. Example 1: Example 2: my code: can't determine the
阅读全文 »
发表于 2018-11-13 20:22阅读:290评论:0推荐:0
摘要:Count the number of prime numbers less than a non-negative number, n. Example: Approach #1: C++. Approach #2: Java. Approach #3: Python.
阅读全文 »
发表于 2018-11-12 19:11阅读:252评论:0推荐:0
摘要:Given a list of unique words, find all pairs of distinct indices (i, j) in the given list, so that the concatenation of the two words, i.e. words[i] +
阅读全文 »
发表于 2018-11-12 12:38阅读:193评论:0推荐:0
摘要:You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time
阅读全文 »
发表于 2018-11-12 11:49阅读:200评论:0推荐:0
摘要: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
阅读全文 »
发表于 2018-11-12 10:59阅读:252评论: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
阅读全文 »
发表于 2018-11-11 22:36阅读:206评论: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
阅读全文 »
发表于 2018-11-11 21:11阅读:172评论:0推荐:0
摘要:Given a binary tree, return the inorder traversal of its nodes' values. Example: Follow up: Recursive solution is trivial, could you do it iteratively
阅读全文 »
发表于 2018-11-10 18:40阅读:351评论:0推荐:0
摘要:A positive integer is magical if it is divisible by either A or B. Return the N-th magical number. Since the answer may be very large, return it modul
阅读全文 »
发表于 2018-11-10 17:51阅读:299评论:0推荐:0
摘要:Koko loves to eat bananas. There are N piles of bananas, the i-th pile has piles[i] bananas. The guards have gone and will come back in H hours. Koko
阅读全文 »
发表于 2018-11-10 17:04阅读:277评论:0推荐:0
摘要:Given a sorted (in ascending order) integer array nums of n elements and a target value, write a function to search target in nums. If targetexists, t
阅读全文 »
发表于 2018-11-10 16:58阅读:297评论:0推荐:0
摘要:Return the length of the shortest, non-empty, contiguous subarray of A with sum at least K. If there is no non-empty subarray with sum at least K, ret
阅读全文 »
发表于 2018-11-09 21:14阅读:225评论:0推荐:0
摘要:Let's call an array A a mountain if the following properties hold: A.length >= 3 There exists some 0 < i < A.length - 1 such that A[0] < A[1] < ... A[
阅读全文 »
发表于 2018-11-09 20:52阅读:300评论:0推荐:0
摘要:Let f(x) be the number of zeroes at the end of x!. (Recall that x! = 1 * 2 * 3 * ... * x, and by convention, 0! = 1.) For example, f(3) = 0 because 3!
阅读全文 »
发表于 2018-11-09 18:48阅读:183评论:0推荐:0
摘要:A sorted list A contains 1, plus some number of primes. Then, for every p < q in the list, we consider the fraction p/q. What is the K-th smallest fra
阅读全文 »
发表于 2018-11-09 16:59阅读:179评论:0推荐:0
摘要:On an N x N grid, each square grid[i][j] represents the elevation at that point (i,j). Now rain starts to fall. At time t, the depth of the water ever
阅读全文 »
发表于 2018-11-08 21:08阅读:184评论:0推荐:0
摘要:Given two integer arrays A and B, return the maximum length of an subarray that appears in both arrays. Example 1: Note: Approach #1: Dynamic programm
阅读全文 »
发表于 2018-11-08 20:48阅读:206评论:0推荐:0
摘要:Given an integer array, return the k-th smallest distance among all the pairs. The distance of a pair (A, B) is defined as the absolute difference bet
阅读全文 »
发表于 2018-11-08 17:34阅读:291评论:0推荐:0
摘要:Nearly every one have used the Multiplication Table. But could you find out the k-th smallest number quickly from the multiplication table? Given the
阅读全文 »
发表于 2018-11-08 16:34阅读:247评论:0推荐:0
摘要:Given a sorted array, two integers k and x, find the k closest elements to x in the array. The result should also be sorted in ascending order. If the
阅读全文 »
发表于 2018-11-07 21:33阅读:329评论:0推荐:0
摘要:For an integer n, we call k>=2 a good base of n, if all digits of n base k are 1. Now given a string representing n, you should return the smallest go
阅读全文 »
发表于 2018-11-07 20:39阅读:278评论:0推荐:0
摘要: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
阅读全文 »
发表于 2018-11-07 19:29阅读:221评论:0推荐:0
摘要:Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero. To make pro
阅读全文 »
发表于 2018-11-06 21:55阅读:216评论:0推荐:0
摘要: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
阅读全文 »
发表于 2018-11-06 21:38阅读:206评论:0推荐:0
摘要:Given a set of intervals, for each of the interval i, check if there exists an interval j whose start point is bigger than or equal to the end point o
阅读全文 »
发表于 2018-11-06 20:28阅读:177评论:0推荐:0
摘要:Given an array which consists of non-negative integers and an integer m, you can split the array into m non-empty continuous subarrays. Write an algor
阅读全文 »
发表于 2018-11-05 17:01阅读:195评论:0推荐:0
摘要:Given a string s and a string t, check if s is subsequence of t. You may assume that there is only lower case English letters in both s and t. t is po
阅读全文 »
发表于 2018-11-05 12:11阅读:157评论:0推荐:0
摘要:Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix. Note that it is th
阅读全文 »
发表于 2018-11-05 09:39阅读:159评论:0推荐:0
摘要:We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to guess which number I picked. Every time you guess wron
阅读全文 »
发表于 2018-11-05 09:24阅读:175评论:0推荐:0
摘要:Given a positive integer num, write a function which returns True if num is a perfect square else False. Note: Do not use any built-in library functio
阅读全文 »
发表于 2018-11-04 22:33阅读:271评论:0推荐:0
摘要:Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix such that its sum is no larger than k. Example: Not
阅读全文 »
发表于 2018-11-04 11:08阅读:266评论:0推荐:0
摘要:You have a number of envelopes with widths and heights given as a pair of integers (w, h). One envelope can fit into another if and only if both the w
阅读全文 »
发表于 2018-11-03 22:38阅读:223评论:0推荐:0
摘要:A peak element is an element that is greater than its neighbors. Given an input array nums, where nums[i] ≠ nums[i+1], find a peak element and return
阅读全文 »
发表于 2018-11-03 22:21阅读:172评论:0推荐:0
摘要:Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist.
阅读全文 »
发表于 2018-11-03 17:16阅读:235评论: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
阅读全文 »
发表于 2018-11-03 15:36阅读:174评论:0推荐:0
摘要:Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted i
阅读全文 »
发表于 2018-11-02 22:37阅读:181评论:0推荐:0
摘要:Given an unsorted array of integers, find the length of longest increasing subsequence. Example: Input: [10,9,2,5,3,7,101,18] Output: 4 Explanation: T
阅读全文 »
发表于 2018-11-01 18:47阅读:147评论:0推荐:0
摘要:code C // Forward declaration of isBadVersion API. bool isBadVersion(int version); class Solution { public: int firstBadVersion(int n) { int l = 1; in
阅读全文 »
发表于 2018-11-01 18:04阅读:154评论:0推荐:0
摘要:You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality c
阅读全文 »
发表于 2018-11-01 17:29阅读:167评论:0推荐:0
摘要:Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn't
阅读全文 »
发表于 2018-11-01 16:46阅读:142评论:0推荐:0
摘要: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
阅读全文 »
发表于 2018-11-01 16:15阅读:150评论:0推荐:0
摘要: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
阅读全文 »