当前位置:网站首页>761. 特殊的二进制序列
761. 特殊的二进制序列
2022-08-10 05:43:00 【anieoo】
原题链接:761. 特殊的二进制序列
solution
class Solution {
public:
static bool cmp(const string &a, const string &b) {
return a > b;
}
string makeLargestSpecial(string s) {
if(s.size() <= 2) return s;
int cnt = 0, left = 0;
vector<string> subs;
for (int i = 0; i < s.size(); ++i) {
if (s[i] == '1') {
++cnt;
}
else {
--cnt;
if (cnt == 0) {
subs.push_back("1" + makeLargestSpecial(s.substr(left + 1, i - left - 1)) + "0");
left = i + 1;
}
}
}
sort(subs.begin(), subs.end(), cmp);
string ans;
for(auto &c : subs) ans += c;
return ans;
}
};
边栏推荐
猜你喜欢
随机推荐
Two-dimensional cartoon rendering of strokes
QEMU guest与host通过网络通信——bridge/hostfwd/guestfwd
XV6系统调用实现
在TypeScript中使用parseInt()
工业废酸回收工艺
优化Mysql运行OrderBy性能
Talking about 3 Common Shadow Rendering Techniques in Games (3): Shadow Mapping
UnityShader入门精要-纹理动画、顶点动画
【备份】《Unity Shader入门精要》配图
Ingress Controller performance test(1)
二次元卡通渲染-着色
Qt程序字体初始化引起的白屏问题
A*Pathfinding插件(3D)
浅谈游戏中3种常用阴影渲染技术(3):阴影贴图
Qt借助隐藏控件和QSS绘制重复元素
Kernel performance analysis summary
Unity插件DOTween使用指南2(简释贝塞尔曲线)
Unity屏幕坐标转世界坐标,鼠标点击获取三维位置
强化学习_12_Datawhale深度确定性策略梯度
Talking about 3 common shadow rendering techniques in games (2): shadow cone