百度前端笔试9.13
单选+多选+编程3题
哎...前面还做了一个笔试...留给百度的时间只有1小时10分钟...
编程1:baidu串(100%)
思路:纯暴力,没啥好说的!只要胆子大,暴力都不怕!
const str = readline(); console.log(fn1(str)); function fn1(str) { if (str.length < 5) return 0; let res = 0; for (let i = 0; i < str.length-4; i++) { let temp = str.slice(i, i+5); if (isValid(temp)) { res++; } } return res; } function isValid(str) { const arr = ['a', 'e', 'i', 'o', 'u']; if ([...new Set([...str])].length < 5) return false; if (arr.includes(str[1]) && arr.includes(str[2]) && arr.includes(str[4]) && !arr.includes(str[0]) && !arr.includes(str[3])) { return true; } else { return false; } }
编程2:01串(100%)
思路:观察0和1的个数
const q = parseInt(readline()); for (let i = 0; i < q; i++) { let str = readline(); fn2(str) ? console.log('Yes') : console.log('No') } function fn2(str) { let arr = [...str].map(item => parseInt(item)); if ([...new Set(arr)].length === 1) return true; let count_1 = 0; let count_0 = 0; for (let item of arr) { item === 1 ? count_1 += 1 : count_0 += 1; } if (count_1 % 2 === 0 || count_0 % 2 === 0) { return true; } else { return false; } }
编程3:踏前斩(5%)
思路:(数组求和sum-最大可减去[1,2,3]个数*6) + 最大可减去[1,2,3]个数*5
来不及做了...随便console.log了一下...