快手工程A卷前三题

靓号题,全过,菜鸡解法,JS写的,凑合看看😂
const checkAsc = (num) => {
    let result = 0;
    let anchor = 0;
    for (let i in num) {
        if (i > 0 && num[i - 1] !== num[i] - 1) {
            anchor = i;
        }
        result = Math.max(result, i - anchor + 1);
    }
    return result;
}; // 检查升序顺子

const checkDesc = (num) => {
    let result = 0;
    let anchor = 0;
    for (let i in num) {
        if (i > 0 && num[i - 1] !== num[i] + 1) {
            anchor = i;
        }
        result = Math.max(result, i - anchor + 1);
    }
    return result;
}; // 检查降序顺子

const checkShunzi = (num) => {
    return Math.max(checkAsc(num), checkDesc(num));
}

const checkLeopard = (num) => {
    let result = 0;
    let anchor = 0;
    for (let i in num) {
        if (i > 0 && num[i - 1] !== num[i]) {
            anchor = i;
        }
        result = Math.max(result, i - anchor + 1);
    }
    return result + 0.5;
} // 检查豹子

const input = readline().split(',');
const result = [];
for (let i in input) {
    const shunzi = checkShunzi(input[i].split('').map(item => parseInt(item)).slice(3));
    const lepard = checkLeopard(input[i].split('').map(item => parseInt(item)).slice(3));
    const weight = Math.max(shunzi, lepard);
    if (weight >= 3) {
        result.push([weight, input[i]]);
    }
}

result.sort((a, b) => a[0] - b[0] < 0);
if (result.length === 0) {
    print(null);
}
else {
    print(result.map(item => item[1]).join(','));
}

第二题,笔试的时候只拿了0.63,下面是修改过的,应该能全过
const input = '2 1 22 22 33 25 55'.split(' ').map(item => parseInt(item));
const result = [];
let max = input[0], smaller = 0;
for (let i in input) {
    if (i == 0) {
        continue;
    }
    if (input[i] < max && input[i] >= smaller) {
        result.push(i);
    }
    else if (input[i] >= max) {
        [smaller, max] = [max, input[i]];
    }
}
console.log(result.length === 0 ? -1 : result.join(' '));

第一题,全过,Python写的
height = [175, 173, 174, 163, 182, 177]
temp = [height[0]]
result = []
flag = False
for item in height:
    flag = False
    for i in range(len(temp)):
        if temp[i] > item:
            flag = True
            result.append(i + 1)
            temp.insert(0, item)
            break
    if flag == False:
        result.append(0)
        temp.insert(0, item)

print(result)


#快手笔试##笔试题目#
全部评论
最后怎么按权重排名的啊
1 回复 分享
发布于 2020-03-22 21:07
体验比美团好多了🤣,许愿面试
点赞 回复 分享
发布于 2020-03-22 21:55

相关推荐

评论
3
1
分享

创作者周榜

更多
牛客网
牛客企业服务