leetcode460. LFU Cache

2020-02-02
阅读 3 分钟
2.3k
Design and implement a data structure for Least Frequently Used (LFU) cache. It should support the following operations: get and put.

leetcode495. Teemo Attacking

2020-02-01
阅读 2 分钟
2k
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 attacking ascending time series towards Ashe and the poisoning time duration per Teemo's attacking, you need to output the total time that Ashe is in poisoned cond...

leetcode543. Diameter of Binary Tree

2020-02-01
阅读 1 分钟
2k
Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may not pass through the root.

leetcode540. Single Element in a Sorted Array

2020-02-01
阅读 2 分钟
2k
You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once. Find this single element that appears only once.

leetcode535. Encode and Decode TinyURL

2020-01-30
阅读 2 分钟
3k
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://tinyurl.com/4e9iAk.

leetcode529. Minesweeper

2020-01-29
阅读 5 分钟
2.2k
You are given a 2D char matrix representing the game board. 'M' represents an unrevealed mine,'E' represents an unrevealed empty square, 'B' represents a revealed blank square that has no adjacent (above, below, left, right, and all 4 diagonals) mines, digit ('1' to '8') represents how many mines...

leetcode542. 01 Matrix

2020-01-27
阅读 4 分钟
2.4k
Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell.

leetcode554. Brick Wall

2020-01-26
阅读 2 分钟
2.2k
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. You want to draw a vertical line from the top to the bottom and cross the least bricks.

leetcode538. Convert BST to Greater Tree

2020-01-26
阅读 2 分钟
2.2k
Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST.

547. Friend Circles

2020-01-19
阅读 3 分钟
2.7k
There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B, and B is a direct friend of C, then A is an indirect friend of C. And we defined a friend circle is a group of students who are direc...

leetcode525. Contiguous Array

2020-01-18
阅读 2 分钟
2k
Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1.

leetcode502. IPO

2020-01-09
阅读 4 分钟
2.1k
Suppose LeetCode will start its IPO soon. In order to sell a good price of its shares to Venture Capital, LeetCode would like to work on some projects to increase its capital before the IPO. Since it has limited resources, it can only finish at most k distinct projects before the IPO. Help LeetCo...

leetcode556. Next Greater Element III

2020-01-07
阅读 2 分钟
2.1k
Given a positive 32-bit integer n, you need to find the smallest 32-bit integer which has exactly the same digits existing in the integer n and is greater in value than n. If no such positive 32-bit integer exists, you need to return -1.

leetcode523. Continuous Subarray Sum

2019-12-31
阅读 3 分钟
1.9k
Given a list of non-negative numbers and a target integer k, write a function to check if the array has a continuous subarray of size at least 2 that sums up to a multiple of k, that is, sums up to n*k where n is also an integer.

leetcode503. Next Greater Element II

2019-12-28
阅读 2 分钟
1.9k
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 element. The Next Greater Number of a number x is the first greater number to its traversing-order next in the array, which means you could search circularly to...

leetcode519. Random Flip Matrix

2019-12-05
阅读 3 分钟
2.3k
You are given the number of rows n_rows and number of columns n_cols of a 2D binary matrix where all values are initially 0. Write a function flip which chooses a 0 value uniformly at random, changes it to 1, and then returns the position [row.id, col.id] of that value. Also, write a function res...

leetcode464. Can I Win

2019-11-30
阅读 3 分钟
2.7k
In the "100 game," two players take turns adding, to a running total, any integer from 1..10. The player who first causes the running total to reach or exceed 100 wins.

leetcode516. Longest Palindromic Subsequence

2019-11-26
阅读 2 分钟
2.3k
Given a string s, find the longest palindromic subsequence's length in s. You may assume that the maximum length of s is 1000.

leetcode480. Sliding Window Median

2019-11-24
阅读 5 分钟
1.8k
Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle value.

513. Find Bottom Left Tree Value

2019-11-17
阅读 1 分钟
1.5k
Given a binary tree, find the leftmost value in the last row of the tree.

leetcode508. Most Frequent Subtree Sum

2019-11-14
阅读 2 分钟
1.6k
Given the root of a tree, you are asked to find the most frequent subtree sum. The subtree sum of a node is defined as the sum of all the node values formed by the subtree rooted at that node (including the node itself). So what is the most frequent subtree sum value? If there is a tie, return al...

leetcode506. Relative Ranks

2019-11-12
阅读 3 分钟
1.6k
Given scores ofNathletes, find their relative ranks and the people with the top three highest scores, who will be awarded medals: "Gold Medal", "Silver Medal" and "Bronze Medal".

leetcode452. Minimum Number of Arrows to Burst Balloons

2019-11-08
阅读 2 分钟
1.5k
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the horizontal diameter. Since it's horizontal, y-coordinates don't matter and hence the x-coordinates of start and end of the diameter suffice. Start is ...

leetcode421. Maximum XOR of Two Numbers in an Array

2019-11-06
阅读 5 分钟
1.6k
Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai< 231.

leetcode472. Concatenated Words

2019-11-01
阅读 3 分钟
2.5k
Given a list of words (without duplicates), please write a program that returns all concatenated words in the given list of words.A concatenated word is defined as a string that is comprised entirely of at least two shorter words in the given array.

leetcode501. Find Mode in Binary Search Tree

2019-10-31
阅读 2 分钟
1.7k
Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST.

leetcode473. Matchsticks to Square

2019-10-30
阅读 3 分钟
1.3k
Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match girl has, please find out a way you can make one square by using up all those matchsticks. You should not break any stick, but you can link them up, and each matchstick must be used exactly one time.

leetcode493. Reverse Pairs

2019-10-29
阅读 3 分钟
1.8k
Given an array nums , we call(i, j)an important reverse pair if i < j andnums[i] > 2*nums[j].

leetcode454. 4Sum II

2019-10-23
阅读 2 分钟
1.3k
采用一些归并排序的思路,假如我们将A,B中所有数字排列组合能够构成的结果计算出来,再将C,D中所有数字的排列组合结果计算出来,则只需要针对AB中的值找到CD中是否有对应的负数存在即可。这里除了要记录数组元素的和,还要记录该求和出现了几次。代码如下:

leetcode446. Arithmetic Slices II - Subsequence

2019-10-15
阅读 3 分钟
1.8k
从一个无序的整数数组中,找到所有等差子数列的数量。这里需要注意,等差子数列要求从原数组中找出Pk个下标的元素,其中P0 < P1 < P2... < Pk,且满足A[P1]-A[P0] = A[P2] - A[P1] ... = A[Pk]-A[Pk-1]。