04 2020 档案
摘要:Problem : Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole arra
阅读全文
摘要:Problem : Given a string, find the length of the longest substring without repeating characters. Example 1: Example 2: Example 3: 思路 : Solution (C++)
阅读全文
摘要:Problem : Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see
阅读全文
摘要:Problem : Given two sequences pushed and popped with distinct values, return true if and only if this could have been the result of a sequence of push
阅读全文
摘要:Problem : Reverse a singly linked list. Example: Follow up: A linked list can be reversed either iteratively or recursively. Could you implement both?
阅读全文
摘要:Problem : Given a matrix which is sorted in non increasing order both row wise and column wise. Return the number of negative numbers in . Example 1:
阅读全文
摘要:Problem : Implement FreqStack, a class which simulates the operation of a stack like data structure. FreqStack has two functions: push(int x), which p
阅读全文
摘要:Problem : Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) Push element x onto stack. pop() R
阅读全文
摘要:Problem : 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
阅读全文
摘要:Problem : Design a stack which supports the following operations. Implement the CustomStack class: CustomStack(int maxSize) Initializes the object wit
阅读全文
摘要:Problem : 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 f
阅读全文
摘要:Problem : You have a list of words and a pattern, and you want to know which words in words matches the pattern. A word matches the pattern if there e
阅读全文
摘要:Problem : Given a positive integer N, find and return the longest distance between two consecutive 1's in the binary representation of N. If there are
阅读全文
摘要:Problem : Given a non empty, singly linked list with head node head, return a middle node of linked list. If there are two middle nodes, return the se
阅读全文
摘要:Problem : Given a matrix A, return the transpose of A. The transpose of a matrix is the matrix flipped over it's main diagonal, switching the row and
阅读全文
摘要:Problem : 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
阅读全文
摘要:Problem : There are N rooms and you start in room 0. Each room has a distinct number in 0, 1, 2, ..., N 1, and each room may have some keys to access
阅读全文
摘要:Problem : Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resulting image. To flip an image horizontal
阅读全文
摘要:Problem : Given a string S and a character C, return an array of integers representing the shortest distance from the character C in the string. Examp
阅读全文
摘要:Problem : A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and uppercase letters only. We would like to c
阅读全文
摘要:Problem : We are given head, the head node of a linked list containing unique integer values. We are also given the list G, a subset of the values in
阅读全文
摘要:Problem : A website domain like "discuss.leetcode.com" consists of various subdomains. At the top level, we have "com", at the next level, we have "le
阅读全文
摘要:Problem : In a 2 dimensional array grid, each value grid[i][j] represents the height of a building located there. We are allowed to increase the heigh
阅读全文
摘要:Problem : We are to write the letters of a given string S, from left to right into lines. Each line has maximum width 100 units, and if writing a lett
阅读全文
摘要:Problem : International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: "a" maps to ".
阅读全文
摘要:Problem : Given a string S, we can transform every letter individually to be lowercase or uppercase to create another string. Return a list of all pos
阅读全文
摘要:Problem : Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a prime number of set bits in their binary repr
阅读全文
摘要:Problem : A matrix is Toeplitz if every diagonal from top left to bottom right has the same element. Now given an M x N matrix, return True if and onl
阅读全文
摘要:Problem : S and T are strings composed of lowercase letters. In S, no letter occurs more than once. S was sorted in some custom order previously. We w
阅读全文
摘要:Problem : Given a directed, acyclic graph of N nodes. Find all possible paths from node 0 to node N 1, and return them in any order. The graph is give
阅读全文
摘要:Problem : Find the minimum length word from a given dictionary words, which has all the letters from the string licensePlate. Such a word is said to c
阅读全文
摘要:Problem : On a staircase, the i th step has some non negative cost cost[i] assigned (0 indexed). Once you pay the cost, you can either climb one or tw
阅读全文
摘要:Problem : Given a list of daily temperatures T, return a list such that, for each day in the input, tells you how many days you would have to wait unt
阅读全文
摘要:Problem : A self dividing number is a number that is divisible by every digit it contains. For example, 128 is a self dividing number because 128 % 1
阅读全文
摘要:Problem : 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 targe
阅读全文
摘要:Problem : Given two strings s1, s2, find the lowest ASCII sum of deleted characters to make two strings equal. Example 1: Example 2: Note: 0 dp(m+1, v
阅读全文
摘要:Problem : Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase. Example 1: Example 2: Example 3:
阅读全文
摘要:Problem : 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 ord
阅读全文
摘要:Problem : You are given a data structure of employee information, which includes the employee's unique id, his importance value and his direct subordi
阅读全文
摘要:Problem : Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values. Example 1:
阅读全文
摘要:Problem : Given a non empty list of words, return the k most frequent elements. Your answer should be sorted by frequency from highest to lowest. If t
阅读全文
摘要:Problem : Give a string s, count the number of non empty (contiguous) substrings that have the same number of 0's and 1's, and all the 0's and all the
阅读全文
摘要:Problem : Given a non empty array of non negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elemen
阅读全文
摘要:Problem : On an NxN chessboard, a knight starts at the r th row and c th column and attempts to make exactly K moves. The rows and columns are 0 index
阅读全文
摘要:Problem : There is a robot starting at position (0, 0), the origin, on a 2D plane. Given a sequence of its moves, judge if this robot ends up at (0, 0
阅读全文
摘要:Problem : Given a non negative integer, you could swap two digits at most once to get the maximum valued number. Return the maximum valued number you
阅读全文
摘要:Problem : Given an unsorted array of integers, find the length of longest continuous increasing subsequence (subarray). Example 1: Example 2: Note: Le
阅读全文
摘要:Problem : You're now a baseball game point recorder. Given a list of strings, each string can be one of the 4 following types: 1. Integer (one round's
阅读全文
摘要:Problem : Initially on a notepad only one character 'A' is present. You can perform two operations on this notepad for each step: 1. Copy All: You can
阅读全文
摘要:Problem : You are given n pairs of numbers. In every pair, the first number is always smaller than the second number. Now, we define a pair (c, d) can
阅读全文
摘要:Problem : Given an integer array, find three numbers whose product is maximum and output the maximum product. Example 1: Example 2: Note: 1. The lengt
阅读全文
摘要:Problem : You are given a string representing an attendance record for a student. The record only contains the following three characters: 1. 'A' : Ab
阅读全文
摘要:Problem : A zero indexed array A of length N contains all integers from 0 to N 1. Find and return the longest length of set S, where S[i] = {A[i], A[A
阅读全文
摘要:Problem : In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new one with different size but keep its orig
阅读全文
摘要:Problem : Given an integer array with even length, where different numbers in this array represent different kinds of candies. Each number means one c
阅读全文
摘要:Problem : We define a harmounious array as an array where the difference between its maximum value and its minimum value is exactly 1. Now, given an i
阅读全文
摘要:Problem : Given an m n matrix M initialized with all 0's and several update operations. Operations are represented by a 2D array, and each operation i
阅读全文
摘要:Problem : Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings. You
阅读全文
摘要:Problem : Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. I
阅读全文
摘要:Problem : You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exa
阅读全文
摘要:Problem : Given a list of 24 hour clock time points in "Hour:Minutes" format, find the minimum minutes difference between any two time points in the l
阅读全文
摘要:Problem : Given two strings representing two complex numbers. You need to return a string representing their multiplication. Note i2 = 1 according to
阅读全文
摘要:Problem : Given a word, you need to judge whether the usage of capitals in it is right or not. We define the usage of capitals in a word to be right w
阅读全文
摘要:Problem : Given an integer, return its base 7 string representation. Example 1: Example 2: Note: The input will be in range of [ 1e7, 1e7]. 思路 : Solut
阅读全文
摘要:Problem : Given a circular array (the next element of the last element is the first element of the array), print the Next Greater Number for every ele
阅读全文
摘要:Problem : In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned condition. Now, given the Teemo's attack
阅读全文
摘要:Problem : Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child
阅读全文
摘要:Problem : 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 horiz
阅读全文
摘要:Problem : For a web developer, it is very important to know how to design a web page's size. So, given a specific rectangular web page’s area, your jo
阅读全文
摘要:Problem : You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers
阅读全文
摘要:Problem : Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Note: 1. The input array will only contain 0 and 1
阅读全文
摘要:Problem : Given a matrix of M x N elements (M rows, N columns), return all elements of the matrix in diagonal order as shown in the below image. Examp
阅读全文
摘要:Problem : 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 be
阅读全文
摘要:Problem : A magical string S consists of only '1' and '2' and obeys the following rules: The string S is magical because concatenating the number of c
阅读全文
摘要:Problem : Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation. Example 1:
阅读全文
摘要:Problem : The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Now your job is to find
阅读全文
摘要:Problem : Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Example 2: Example 3: 思路 : Solution (C++) : 性能
阅读全文
摘要:Problem : 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 t
阅读全文
摘要:Problem : Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements that
阅读全文
摘要:Problem : Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If n is odd, you can replace n with either
阅读全文
摘要:Problem : A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elemen
阅读全文
摘要:Problem : 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 tim
阅读全文
摘要:Problem : 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 n
阅读全文
摘要:Problem : Given an array of integers with possible duplicates, randomly output the index of a given target number. You can assume that the given targe
阅读全文
摘要:Problem : Given an array of integers A and let n to be its length. Assume Bk to be an array obtained by rotating the array A k positions clock wise, w
阅读全文
摘要:Problem : A character in UTF8 can be from 1 to 4 bytes long, subjected to the following rules: For 1 byte character, the first bit is a 0, followed by
阅读全文
摘要:Problem : Given an encoded string, return its decoded string. The encoding rule is: k[encoded_string], where the encoded_string inside the square brac
阅读全文
摘要:Problem : 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
阅读全文
摘要:Problem : Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true i
阅读全文
摘要:Problem : Given a singly linked list, return a random node's value from the linked list. Each node must have the same probability of being chosen. Fol
阅读全文
摘要:Problem : Given an integer n, return 1 n in lexicographical order. For example, given 13, return: [1,10,11,12,13,2,3,4,5,6,7,8,9]. Please optimize you
阅读全文
摘要:Problem : 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 tha
阅读全文
摘要:Problem : Your task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of an arr
阅读全文
摘要:Problem : Given a non negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Example: 思路 : Solution (C++) : 性能 : Runtime: 0 m
阅读全文
摘要:Problem : Write a function that takes a string as input and reverse only the vowels of a string. Example 1: Example 2: Note: The vowels does not inclu
阅读全文
摘要:Problem : Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the m
阅读全文
摘要:Problem : Given a non empty array of integers, return the k most frequent elements. Example 1: Example 2: Note: You may assume k is always valid, 1 ≤
阅读全文
摘要:Problem : Write a function that reverses a string. The input string is given as an array of characters char[]. Do not allocate extra space for another
阅读全文
摘要:Problem : Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representa
阅读全文
摘要:Problem : Given an integer, write a function to determine if it is a power of three. Example 1: Example 2: Example 3: Example 4: Follow up: Could you
阅读全文
摘要:Problem : Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example 1: Example 2: Follow up: Could you solve it
阅读全文
摘要:Problem : 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
阅读全文
摘要:Problem : You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the
阅读全文
摘要:Problem : Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3,
阅读全文
摘要:Problem : Given an array, rotate the array to the right by k steps, where k is non negative. Example 1: Example 2: Note: Try to come up as many soluti
阅读全文
摘要:Problem : Reverse bits of a given 32 bits unsigned integer. Example 1: Example 2: Note: 思路 : Solution (C++) : 性能 : Runtime: 4 ms Memory Usage: 6.7 MB
阅读全文
摘要:Problem : Given an integer n, return the number of trailing zeroes in n!. Example 1: Example 2: Note: Your solution should be in logarithmic time comp
阅读全文
摘要:Problem : Given a positive integer, return its corresponding column title as appear in an Excel sheet. For example: Example 1: Example 2: Example 3: 思
阅读全文
摘要:Problem : Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. Th
阅读全文
摘要:Problem : 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 a
阅读全文
摘要:Problem : Given an integer, write a function to determine if it is a power of two. Example 1: Example 2: Example 3: `` Input: 218 Output: false c bool
阅读全文
摘要:Problem : Count the number of prime numbers less than a non negative number, n. Example: 思路 : Solution (C++) : 性能 : Runtime: 208 ms Memory Usage: 6.6
阅读全文
摘要:Problem : 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
阅读全文
摘要:Problem : Remove all elements from a linked list of integers that have value val. Example: 思路 : Solution (C++) : 性能 : Runtime: 44 ms Memory Usage: 10.
阅读全文
摘要:Problem : Given a list of non negative integers, arrange them such that they form the largest number. Example 1: Example 2: Note: The result may be ve
阅读全文
摘要:Problem : Given an array A of non negative integers, half of the integers in A are odd, and half of the integers are even. Sort the array so that when
阅读全文
摘要:Problem : Given two arrays, write a function to compute their intersection. Example 1: Example 2: Note: Each element in the result must be unique. The
阅读全文
摘要:Problem : Given two strings s and t , write a function to determine if t is an anagram of s. Example 1: Example 2: Note: You may assume the string con
阅读全文
摘要:Problem : Given an unsorted array, find the maximum difference between the successive elements in its sorted form. Return 0 if the array contains less
阅读全文
摘要:Problem : 思路 : Solution (C++) : 性能 : Runtime: 60 ms Memory Usage: 8.6 MB 思路 : Solution (C++) : 性能 : Runtime: ms Memory Usage: MB
阅读全文
摘要:Problem : 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 an
阅读全文
摘要:Problem : 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,
阅读全文
摘要:Problem : The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and
阅读全文
摘要:Problem : 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
阅读全文
摘要:Problem : Write a program that outputs the string representation of numbers from 1 to n. But for multiples of three it should output “Fizz” instead of
阅读全文