当前位置:网站首页>761. Special Binary Sequences
761. Special Binary Sequences
2022-08-10 06:35:00 【anieoo】
Original title link: 761. Special Binary Sequence
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 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;}};
边栏推荐
猜你喜欢
随机推荐
Kernel Image File Format
如何在AdsPower中设置YiLu代理?
语法基础(判断语句)
unity箭头控制物体移动
网页安全证书错误但无法安装证书的解决办法
2022河南萌新联赛第(五)场:信息工程大学 J - AC自动机
H3C文档NAT专题
Parallax Mapping: More Realistic Texture Detail Representation (Part 1): Why Use Parallax Mapping
全网可达,交换机和路由器的配置,vlan
qemu and host share disk
761. 特殊的二进制序列
2022 Henan Mengxin League No. 5: University of Information Engineering J-AC Automata
动态规划——从0-1背包问题到leetcode正则匹配
Qt借助隐藏控件和QSS绘制重复元素
QScroller的QScrollerProperties参数研究
Introduction to KDE Framework
Unity扩展编辑器EditorWindow 小玩意(一)
Log4j2基本使用
深入理解数组
Ingress Controller performance test(1)