add: descriptions

This commit is contained in:
Lam Haoyin 2022-01-24 12:20:10 +08:00
parent 00f8a165fb
commit 1cc8cacde1
No known key found for this signature in database
GPG Key ID: 8C089CB1A2B7544F
4 changed files with 42 additions and 1 deletions

View File

@ -1,5 +1,12 @@
#include <vector> #include <vector>
/**
* 2029. Stone Game IX
* Alice and Bob continue their games with stones. There is a row of n stones, and each stone has an associated value. You are given an integer array stones, where stones[i] is the value of the ith stone.
* Alice and Bob take turns, with Alice starting first. On each turn, the player may remove any stone from stones. The player who removes a stone loses if the sum of the values of all removed stones is divisible by 3. Bob will win automatically if there are no remaining stones (even if it is Alice's turn).
* Assuming both players play optimally, return true if Alice wins and false if Bob wins.
*/
class Solution { class Solution {
public: public:
static bool stoneGameIX(const std::vector<int>& stones) { static bool stoneGameIX(const std::vector<int>& stones) {

View File

@ -1,6 +1,13 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <queue>
/**
* 875. Koko Eating Bananas
* Koko loves to eat bananas. There are n piles of bananas, the ith pile has piles[i] bananas. The guards have gone and will come back in h hours.
* Koko can decide her bananas-per-hour eating speed of k. Each hour, she chooses some pile of bananas and eats k bananas from that pile. If the pile has less than k bananas, she eats all of them instead and will not eat any more bananas during this hour.
* Koko likes to eat slowly but still wants to finish eating all the bananas before the guards return.
* Return the minimum integer k such that she can eat all the bananas within h hours.
*/
class Solution { class Solution {
public: public:

View File

@ -6,6 +6,27 @@
#include <set> #include <set>
#include <unordered_map> #include <unordered_map>
/**
* 2034. Stock Price Fluctuation
* You are given a stream of records about a particular stock. Each record contains a timestamp and the corresponding price of the stock at that timestamp.
*
* Unfortunately due to the volatile nature of the stock market, the records do not come in order. Even worse, some records may be incorrect. Another record with the same timestamp may appear later in the stream correcting the price of the previous wrong record.
*
* Design an algorithm that:
*
* Updates the price of the stock at a particular timestamp, correcting the price from any previous records at the timestamp.
* Finds the latest price of the stock based on the current records. The latest price is the price at the latest timestamp recorded.
* Finds the maximum price the stock has been based on the current records.
* Finds the minimum price the stock has been based on the current records.
* Implement the StockPrice class:
*
* StockPrice() Initializes the object with no price records.
* void update(int timestamp, int price) Updates the price of the stock at the given timestamp.
* int current() Returns the latest price of the stock.
* int maximum() Returns the maximum price of the stock.
* int minimum() Returns the minimum price of the stock.
*/
class StockPrice { class StockPrice {
private: private:
std::unordered_map<int, int> m; std::unordered_map<int, int> m;

View File

@ -27,6 +27,12 @@ struct TableGenerator {
} }
}; };
/**
* 1291. Sequential Digits
* An integer has sequential digits if and only if each digit in the number is one more than the previous digit.
* Return a sorted list of all the integers in the range [low, high] inclusive that have sequential digits.
*/
class Solution { class Solution {
private: private:
inline static constexpr TableGenerator<10, 1000000000> table; inline static constexpr TableGenerator<10, 1000000000> table;