当前位置:网站首页>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();}
边栏推荐
猜你喜欢
「应用架构」六边型架构:三个原则和一个实现示例
06 【生命周期 模板引用】
LCD DRM驱动框架分析一
数据中台解决方案及未来发展方向
The web project accesses static resources inside the reference jar
"Microservice Architecture" Arrangement and Choreography - Different Models for Making Systems Work Together
12 【其它组合式API】
Static关键字及应用,继承的概念
PostgreSQL 2022 发展现状:13 个非 psql 工具
CatchAdmin实战教程(四)Table组件之自定义基础页面
随机推荐
【物联网架构】最适合物联网的开源数据库
【分布式】资源与事务:可观测性的基本二重性
反射效率为什么低?
杭电多校七 1008-Triangle Game(博弈)
04 【计算属性 侦听器】
Controller层代码这么写,简洁又优雅!
08 【Props 组件事件】
"Microservice Architecture" Arrangement and Choreography - Different Models for Making Systems Work Together
数据库的约束
哈希表,哈希桶的实现
【Prometheus】Node Exporter常用查询PromQL 语句大总结
Tencent releases the second-generation version of the quadruped robot Max, which completes jumps and somersaults on the plum blossom pile
14道高频手写JS面试题及答案,巩固你的JS基础
解决问题目录
ELK入门
Property animation QPropertyAnimation
Which is the strongest workflow engine for "Technology Selection"?Chief Architecture Helps You Pick
Fourier series and Fourier transform
【数据架构】概念数据模型和逻辑数据模型有什么区别
LCD模块如何建立联系分析