题解 | #农场智能管理系统#
农场智能管理系统
https://www.nowcoder.com/practice/a1461ace00224e5a9fc6ff3d1ae587e5
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param requirements string字符串
* @param allocations string字符串
* @return string字符串
*/
function can_construct(requirements, allocations) {
// write code here
let reqObj = {};
let allocObj = {};
for (const key of requirements) {
if (!reqObj.hasOwnProperty(key)) {
reqObj[key] = 1;
} else {
reqObj[key]++;
}
}
for (const key of allocations) {
if (!allocObj.hasOwnProperty(key)) {
allocObj[key] = 1;
} else {
allocObj[key]++;
}
}
if (Object.keys(reqObj).length !== Object.keys(allocObj).length) {
return 'NO'
}
for (const key of Object.keys(reqObj)) {
if (reqObj[key] > allocObj[key] || !allocObj[key]) {
return 'NO'
}
}
return 'YES'
}
module.exports = {
can_construct: can_construct,
};
阿里巴巴公司氛围 653人发布
查看30道真题和解析