leetcode Count of Smaller Numbers After Self
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 smaller elements to the right ofnums[i]
.Example:
Given nums = [5, 2, 6, 1]
To the right of 5 there are 2 smaller elements (2 and 1). To the right of 2 there is only 1 smaller element (1). To the right of 6 there is 1 smaller element (1). To the right of 1 there is 0 smaller element.
Return the array
[2, 1, 1, 0]
.
windows 10 远程桌面提示凭证无法工作解决办法
leetcode Super Ugly Number
leetcode Super Ugly Number
Write a program to find the nth super ugly number.
Super ugly numbers are positive numbers whose all prime factors are in the given prime list
primes
of sizek
. For example,[1, 2, 4, 7, 8, 13, 14, 16, 19, 26, 28, 32]
is the sequence of the first 12 super ugly numbers givenprimes
=[2, 7, 13, 19]
of size 4.Note: (1)
1
is a super ugly number for any givenprimes
. (2) The given numbers inprimes
are in ascending order. (3) 0 <k
≤ 100, 0 <n
≤ 106, 0 <primes[i]
< 1000.
leetcode Ugly Number I II
leetcode Ugly Number
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, 5
. For example,6, 8
are ugly while14
is not ugly since it includes another prime factor7
.Note that
1
is typically treated as an ugly number.
leetcode Burst Balloons
leetcode Burst Balloons
Given
n
balloons, indexed from0
ton-1
. Each balloon is painted with a number on it represented by arraynums
. You are asked to burst all the balloons. If the you burst ballooni
you will getnums[left] * nums[i] * nums[right]
coins. Hereleft
andright
are adjacent indices ofi
. After the burst, theleft
andright
then becomes adjacent.Find the maximum coins you can collect by bursting the balloons wisely.
Note: (1) You may imagine
nums[-1] = nums[n] = 1
. They are not real therefore you can not burst them. (2) 0 ≤n
≤ 500, 0 ≤nums[i]
≤ 100Example:
Given
[3, 1, 5, 8]
Return
167
1
2 nums = [3,1,5,8] --> [3,5,8] --> [3,8] --> [8] --> []
coins = 3*1*5 + 3*5*8 + 1*3*8 + 1*8*1 = 167
Chrome Vimium 插件
Chrome 下的 Vimium 插件 可以让你在浏览 网页的时候 摆脱鼠标的使用。 博主现在拿着无线键盘,都比较随意的拿起键盘放在舒适的位置。 有时候离鼠标比较远,浏览个网页点击然后再去拿鼠标是很不爽的~~~ 于是,该神器登场的时候到了 ~
leetcode Minimum Height Trees
leetcode Minimum Height Trees
For a undirected graph with tree characteristics, we can choose any node as the root. The result graph is then a rooted tree. Among all possible rooted trees, those with minimum height are called minimum height trees (MHTs). Given such a graph, write a function to find all the MHTs and return a list of their root labels.
Format The graph contains
n
nodes which are labeled from0
ton - 1
. You will be given the numbern
and a list of undirectededges
(each edge is a pair of labels).You can assume that no duplicate edges will appear in
edges
. Since all edges are undirected,[0, 1]
is the same as[1, 0]
and thus will not appear together inedges
.Example 1:
Given
n = 4
,edges = [[1, 0], [1, 2], [1, 3]]
1
2
3
4
5 0
1
/ \
2 3return
[1]
leetcode Best Time to Buy and Sell Stock with Cooldown
leetcode Best Time to Buy and Sell Stock with Cooldown
Say you have an array for which the _i_th element is the price of a given stock on day i.
Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times) with the following restrictions:
- You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).
- After you sell your stock, you cannot buy stock on next day. (ie, cooldown 1 day)
Example:
prices = [1, 2, 3, 0, 2]
maxProfit = 3
transactions = [buy, sell, cooldown, buy, sell]
leetcode First Bad Version
leetcode First Bad Version
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 check. Since each version is developed based on the previous version, all the versions after a bad version are also bad.
Suppose you have
n
versions[1, 2, ..., n]
and you want to find out the first bad one, which causes all the following ones to be bad.You are given an API
bool isBadVersion(version)
which will return whetherversion
is bad. Implement a function to find the first bad version. You should minimize the number of calls to the API.
leetcode Count Primes
leetcode Count Primes
Description:
Count the number of prime numbers less than a non-negative number, n.