当前位置:网站首页>2022.8.8-----leetcode.761
2022.8.8-----leetcode.761
2022-08-10 10:04:00 【Road Lu727】
public String makeLargestSpecial(String s) {//If 1 is (, 0 is), then s can be regarded as a legal bracket sequence with only one pair of brackets in the outermost layer#//Remove the outermost layer, it can be divided into several #, they belong to the same layer//One operation is to sort the # of the same layer to get the maximum resultif (s.length() == 0) return s;List list = new ArrayList<>();char[] cs = s.toCharArray();//Remove the outermost layer of the # of the previous layer, and divide it to get this layer#for (int i = 0, j = 0, k = 0; i < cs.length; i++) {k += cs[i] == '1' ? 1 : -1;//When k=0, get a complete#if (k == 0) {String next=makeLargestSpecial(s.substring(j + 1, i));//Remove the outermost layer and enter the next layer of sortinglist.add("1" + next + "0");//After sorting the next time, add the outermost layerj = i + 1;}}Collections.sort(list, (a, b)->(b + a).compareTo(a + b));//Sort this layerStringBuilder sb = new StringBuilder();for (String str : list) sb.append(str);//Splicing returnreturn sb.toString();}
边栏推荐
猜你喜欢
随机推荐
VBA: 采用Combox控件实现二级下拉菜单功能
12 【其它组合式API】
JS高级 之 使用 Iterator - Generator
【软考 系统架构设计师】案例分析⑥ Web应用系统架构设计
07 【动态组件 组件注册】
04 【计算属性 侦听器】
dedecms支持Word内容一键上传
【数据架构】概念数据模型和逻辑数据模型有什么区别
"Microservice Architecture" Arrangement and Choreography - Different Models for Making Systems Work Together
C语言题解:倒置字符串
在兄弟连战狼班参加PHP培训做行业领先人才
ESP8266 Tutorial 2 - Burn AT Firmware
「数据战略」结果驱动的企业数据策略:组织和治理
定时任务Quartz
「敏捷建模」纪律:敏捷设计理念
Lasso回归(Stata)
ESP8266 教程1 — ESP8266硬件平台介绍
SQL中的字符串截取函数
在“企业通讯录”的盲区,融云的边界与分寸
Lasso regression (Stata)