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 374. Guess Number Higher or Lower

LeetCode 374. Guess Number Higher or Lower

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 is higher or lower.

You call a pre-defined API guess(int num) which returns 3 possible results (-1, 1, or 0):

-1 : My number is lower
1 : My number is higher
0 : Congrats! You got it!
Example :

Input: n = 10, pick = 6
Output: 6

继续阅读
LeetCode 365. Water and Jug Problem

LeetCode 365. Water and Jug Problem

Description
You are given two jugs with capacities x and y litres. There is an infinite amount of water supply available. You need to determine whether it is possible to measure exactly z litres using these two jugs.

If z liters of water is measurable, you must have z liters of water contained within one or both buckets by the end.

Operations allowed:

Fill any of the jugs completely with water.
Empty any of the jugs.
Pour water from one jug into another till the other jug is completely full or the first jug itself is empty.

继续阅读