您当前的位置: 首页 >  面试

庄小焱

暂无认证

  • 3浏览

    0关注

    805博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

牛客网算法——名企高频面试题143题(0)

庄小焱 发布时间:2020-07-06 08:27:34 ,浏览量:3

简明题意:

我们定义一个整数可重集合是好的,当且仅当对于集合中任意两个元素 a, b (a≤ba \leq ba≤b) ,所有满足 a≤c≤ba\leq c\leq ba≤c≤b 的元素 c 都在集合中出现过。

现在,给你一个数组 mSet,你需要做的是,对于这个数组的每一个前缀,判断这个前缀是不是一个好的集合。所以,你将计算出的是一个数组,为布尔类型。

输入
[3,5,4,6]
输出
[true,false,true,true]
说明

第一个前缀只有一个元素3,按照好的集合的定义,它显然是连续的。

第二个前缀有一个3和一个5,位于3和5之间的元素4却不在集合中,所以它不是连续的。

第三个前缀添加了一个4,弥补了第二个集合缺少4的问题,所以它是好的。

第四个前缀新增了一个6,依旧连续。

/**
 * Copyright (C), 2018-2020
 * FileName: continuousSet
 * Author:   xjl
 * Date:     2020/7/5 16:44
 * Description: 排序算法
 */
package Sort;

import org.junit.Test;

import java.util.*;

public class continuousSet {
    //通过率64
    public boolean[] continuousSet(int[] mSet) {
        //返回的结果
        boolean[] result = new boolean[mSet.length];
        ArrayList list = new ArrayList();
        for (int i = 0; i < mSet.length; i++) {
            //添加元素
            list.add(mSet[i]);
            //选择第一个
            int start = Collections.min(list);
            int end = Collections.max(list);
            int flag = 0;
            //检查是否有序
            while (start  Math.pow(10,7)){
            return number;
        }
        char[] temp = number.toCharArray();
        int left = 0;
        int right = temp.length - 1;

        while(left < right){
            if(temp[left]%2!=0){
                left++;
                continue;
            }
            if(temp[right]%2!=0){
                right--;
                continue;
            }
            
            char tempNum = temp[left];
            temp[left] = temp[right];
            temp[right] = tempNum;
            left++;
            right--;
        }
        return String.valueOf(temp);
    }
}
关注
打赏
1657692713
查看更多评论
立即登录/注册

微信扫码登录

0.0827s