add: 230411
This commit is contained in:
parent
873ac4de1e
commit
dab70cedf8
|
|
@ -0,0 +1,33 @@
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 2390. Removing Stars From a String
|
||||||
|
*
|
||||||
|
* You are given a string s, which contains stars *.
|
||||||
|
*
|
||||||
|
* In one operation, you can:
|
||||||
|
*
|
||||||
|
* Choose a star in s.
|
||||||
|
* Remove the closest non-star character to its left, as well as remove the star itself.
|
||||||
|
* Return the string after all stars have been removed.
|
||||||
|
*
|
||||||
|
* Note:
|
||||||
|
*
|
||||||
|
* The input will be generated such that the operation is always possible.
|
||||||
|
* It can be shown that the resulting string will always be unique.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
static std::string removeStars(const std::string&);
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string Solution::removeStars(const std::string& s) {
|
||||||
|
std::string ret;
|
||||||
|
for (char ch : s)
|
||||||
|
if (ch != '*')
|
||||||
|
ret.push_back(ch);
|
||||||
|
else
|
||||||
|
ret.pop_back();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
@ -4,4 +4,4 @@ PROJECT(2304)
|
||||||
SET(CMAKE_CXX_STANDARD 23)
|
SET(CMAKE_CXX_STANDARD 23)
|
||||||
SET(CMAKE_EXPORT_COMPILE_COMMANDS true)
|
SET(CMAKE_EXPORT_COMPILE_COMMANDS true)
|
||||||
|
|
||||||
ADD_EXECUTABLE(2304 230410.cpp)
|
ADD_EXECUTABLE(2304 230411.cpp)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue