当前位置:网站首页>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;
}
};边栏推荐
猜你喜欢
随机推荐
UnityShader入门精要-纹理动画、顶点动画
Two-dimensional cartoon rendering of strokes
R language cluster analysis - code analysis
强化学习_06_pytorch-DQN实践(CartPole-v0)
初学者也能看懂的Ray March体积云
新手使用 go channel 需要注意的问题
unity瓦片地图调整图片大小
Analysis of minix_super_block.s_ninodes of mkfs.minix.c
Unity的GetComponentsInChildren1、2、3
Parallax Mapping: More Realistic Texture Detail Representation (Part 1): Why Use Parallax Mapping
Unity2D动画生成操作(简单)
Win32屏幕坐标转换Qt坐标
老手也常误用!详解 Go channel 内存泄漏问题
Mysql表数据在命令行窗口下中文乱码问题解决方法
剑指 Offer(第 2 版)7/6 9-13
二叉树 6/15 76-80
UnityShader入门精要-unity shader基础
Screen post-processing: Sobel operator to achieve edge detection
Unity2d自动寻路(AI插件)
Make a boot floppy and boot with bochs emulator








