LeetCode 376. Wiggle Subsequence

LeetCode 376. Wiggle Subsequence

Description
A sequence of numbers is called a wiggle sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with fewer than two elements is trivially a wiggle sequence.

继续阅读
2019-07-12-LD-买切糕

LD Buy Cut Cake

描述
LD 是个众所周知的糕富帅,从不把买切糕的钱当钱,只求量和品质,不惜价。但他还是会纠结买哪些切糕好,现假设切糕的价钱有 5 种分别为每两 2,2.5,3,3.5,4(百RMB),并且数量都假设为无限。现在告诉你 LD 一共有几百 RMB。请你告诉 LD 他一共有几种买切糕的方案(钱可以不花光,但一定要买,不花钱 LD 会不开心的)。

继续阅读
LeetCode 375. Guess Number Higher or Lower II

LeetCode 375. Guess Number Higher or Lower II

Description
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 wrong, I’ll tell you whether the number I picked is higher or lower.

However, when you guess a particular number x, and you guess wrong, you pay $x. You win the game when you guess the number I picked.

Example:

n = 10, I pick 8.

First round: You guess 5, I tell you that it’s higher. You pay 5. Second round: You guess 7, I tell you that it’s higher. You pay5.Secondround:Youguess7,Itellyouthatit

shigher.Youpay7.
Third round: You guess 9, I tell you that it’s lower. You pay $9.

Game over. 8 is the number I picked.

You end up paying 5 +5+7 + 9 =9=21.
Given a particular n ≥ 1, find out how much money you need to have to guarantee a win.

继续阅读
LeetCode 363. Max Sum of Rectangle No Larger Than K

LeetCode 363. Max Sum of Rectangle No Larger Than K

Description
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:

Input: matrix = [[1,0,1],[0,-2,3]], k = 2
Output: 2
Explanation: Because the sum of rectangle [[0, 1], [-2, 3]] is 2,
and 2 is the max number no larger than k (k = 2).
Note:

The rectangle inside the matrix must have an area > 0.
What if the number of rows is much larger than the number of columns?

继续阅读