博客
关于我
力扣:修改后的最大二进制字符串
阅读量:403 次
发布时间:2019-03-05

本文共 1471 字,大约阅读时间需要 4 分钟。

??????????????????????????????????????1??00?????10????2??10?????01???????????????????????????1?????????????

????

  • ??0?????????????0??????????
  • ?????0???????????????????0????????10??
  • ?????????????0??????????????????????0????
  • ???????????????0??????????1?????????????

    ????

    import java.util.ArrayList;import java.util.List;public class Solution {    public String maximumBinaryString(String binary) {        char[] chars = binary.toCharArray();        int length = chars.length;        List
    zeroPositions = new ArrayList<>(); // ????0??? for (int i = 0; i < length; i++) { if (chars[i] == '0') { zeroPositions.add(i); } } // ?????????0 for (int i = zeroPositions.size() - 2; i >= 0; i--) { int current = zeroPositions.get(i); int next = zeroPositions.get(i + 1); if (next == current + 1) { // ???10 chars[current] = '1'; chars[next] = '0'; // ??zeroPositions???current?next???????? zeroPositions.remove(i); zeroPositions.remove(i); zeroPositions.add(next); } } return new String(chars); }}

    ????

  • ??0??????????????0????zeroPositions????
  • ?????0???????zeroPositions????????0????????10??
  • ?????????????0????zeroPositions????????????????0????
  • ??????????????????????0???1?????????????

    转载地址:http://wrjzz.baihongyu.com/

    你可能感兴趣的文章
    npm报错unable to access ‘https://github.com/sohee-lee7/Squire.git/‘
    查看>>
    npm的常用配置项---npm工作笔记004
    查看>>
    npm的问题:config global `--global`, `--local` are deprecated. Use `--location=global` instead 的解决办法
    查看>>
    npm编译报错You may need an additional loader to handle the result of these loaders
    查看>>
    npm配置安装最新淘宝镜像,旧镜像会errror
    查看>>
    npm错误Error: Cannot find module ‘postcss-loader‘
    查看>>
    NPOI之Excel——合并单元格、设置样式、输入公式
    查看>>
    NPOI利用多任务模式分批写入多个Excel
    查看>>
    NPOI在Excel中插入图片
    查看>>
    NPOI格式设置
    查看>>
    Npp删除选中行的Macro录制方式
    查看>>
    NR,NF,FNR
    查看>>
    nrf开发笔记一开发软件
    查看>>
    NS3 IP首部校验和
    查看>>
    NSDateFormatter的替代方法
    查看>>
    NSError 的使用方法
    查看>>
    nsis 安装脚本示例(转)
    查看>>
    NSJSON的用法(oc系统自带的解析方法)
    查看>>
    nslookup 的基本知识与命令详解
    查看>>
    NSOperation基本操作
    查看>>