add: descriptions

This commit is contained in:
Lam Haoyin 2022-01-28 19:39:59 +08:00
parent 06152cca83
commit 1674b91428
No known key found for this signature in database
GPG Key ID: 8C089CB1A2B7544F
5 changed files with 54 additions and 0 deletions

View File

@ -1,6 +1,17 @@
#include <string> #include <string>
#include <iostream> #include <iostream>
/**
* 1332. Remove Palindromic Subsequences
* You are given a string s consisting only of letters 'a' and 'b'. In a single step you can remove one palindromic subsequence from s.
*
* Return the minimum number of steps to make the given string empty.
*
* A string is a subsequence of a given string if it is generated by deleting some characters of a given string without changing its order. Note that a subsequence does not necessarily need to be contiguous.
*
* A string is called palindrome if is one that reads the same backward as well as forward.
*/
class Solution { class Solution {
public: public:
static int removePalindromeSub(const std::string& s) { static int removePalindromeSub(const std::string& s) {

View File

@ -57,6 +57,21 @@ public:
} }
}; };
/**
* 2013. Detect Squares
* You are given a stream of points on the X-Y plane. Design an algorithm that:
*
* Adds new points from the stream into a data structure. Duplicate points are allowed and should be treated as different points.
* Given a query point, counts the number of ways to choose three points from the data structure such that the three points and the query point form an axis-aligned square with positive area.
* An axis-aligned square is a square whose edges are all the same length and are either parallel or perpendicular to the x-axis and y-axis.
*
* Implement the DetectSquares class:
*
* DetectSquares() Initializes the object with an empty data structure.
* void add(int[] point) Adds a new point point = [x, y] to the data structure.
* int count(int[] point) Counts the number of ways to form axis-aligned squares with point point = [x, y] as described above.
*/
class DetectSquares { class DetectSquares {
private: private:
std::unordered_multiset<int> indexX[1002], indexY[1002]; std::unordered_multiset<int> indexX[1002], indexY[1002];

View File

@ -11,6 +11,11 @@ struct TreeNode {
explicit TreeNode(int x = 0, TreeNode* left = nullptr, TreeNode* right = nullptr) : val(x), left(left), right(right) {} explicit TreeNode(int x = 0, TreeNode* left = nullptr, TreeNode* right = nullptr) : val(x), left(left), right(right) {}
}; };
/**
* 1305. All Elements in Two Binary Search Trees
* Given two binary search trees root1 and root2, return a list containing all the integers from both trees sorted in ascending order.
*/
class Solution { class Solution {
private: private:
static void dfs(const TreeNode* const root, std::vector<int>& ret) { static void dfs(const TreeNode* const root, std::vector<int>& ret) {

View File

@ -1,6 +1,20 @@
#include <string> #include <string>
#include <cctype> #include <cctype>
/**
* 2047. Number of Valid Words in a Sentence
* A sentence consists of lowercase letters ('a' to 'z'), digits ('0' to '9'), hyphens ('-'), punctuation marks ('!', '.', and ','), and spaces (' ') only. Each sentence can be broken down into one or more tokens separated by one or more spaces ' '.
*
* A token is a valid word if all three of the following are true:
*
* It only contains lowercase letters, hyphens, and/or punctuation (no digits).
* There is at most one hyphen '-'. If present, it must be surrounded by lowercase characters ("a-b" is valid, but "-ab" and "ab-" are not valid).
* There is at most one punctuation mark. If present, it must be at the end of the token ("ab,", "cd!", and "." are valid, but "a!b" and "c.," are not valid).
* Examples of valid words include "a-b.", "afad", "ba-c", "a!", and "!".
*
* Given a string sentence, return the number of valid words in sentence.
*/
class Solution { class Solution {
private: private:
static bool isOK(const std::string& t) { static bool isOK(const std::string& t) {

View File

@ -1,6 +1,15 @@
#include <vector> #include <vector>
#include <iostream> #include <iostream>
/**
* 1996. The Number of Weak Characters in the Game
* You are playing a game that contains multiple characters, and each of the characters has two main properties: attack and defense. You are given a 2D integer array properties where properties[i] = [attacki, defensei] represents the properties of the ith character in the game.
*
* A character is said to be weak if any other character has both attack and defense levels strictly greater than this character's attack and defense levels. More formally, a character i is said to be weak if there exists another character j where attackj > attacki and defensej > defensei.
*
* Return the number of weak characters.
*/
class Solution { class Solution {
public: public:
static int numberOfWeakCharacters(std::vector<std::vector<int>>& properties) { static int numberOfWeakCharacters(std::vector<std::vector<int>>& properties) {