LeetCode每日一题——2525. Categorize Box According to Criteria

文章目录

一、题目

Given four integers length, width, height, and mass, representing the dimensions and mass of a box, respectively, return a string representing the category of the box.

The box is "Bulky" if:

Any of the dimensions of the box is greater or equal to 104.

Or, the volume of the box is greater or equal to 109.

If the mass of the box is greater or equal to 100, it is "Heavy".

If the box is both "Bulky" and "Heavy", then its category is "Both".

If the box is neither "Bulky" nor "Heavy", then its category is "Neither".

If the box is "Bulky" but not "Heavy", then its category is "Bulky".

If the box is "Heavy" but not "Bulky", then its category is "Heavy".

Note that the volume of the box is the product of its length, width and height.

Example 1:

Input: length = 1000, width = 35, height = 700, mass = 300

Output: "Heavy"

Explanation:

None of the dimensions of the box is greater or equal to 104.

Its volume = 24500000 <= 109. So it cannot be categorized as "Bulky".

However mass >= 100, so the box is "Heavy".

Since the box is not "Bulky" but "Heavy", we return "Heavy".

Example 2:

Input: length = 200, width = 50, height = 800, mass = 50

Output: "Neither"

Explanation:

None of the dimensions of the box is greater or equal to 104.

Its volume = 8 * 106 <= 109. So it cannot be categorized as "Bulky".

Its mass is also less than 100, so it cannot be categorized as "Heavy" either.

Since its neither of the two above categories, we return "Neither".

Constraints:

1 <= length, width, height <= 105

1 <= mass <= 103

二、题解

cpp 复制代码
class Solution {
public:
    string categorizeBox(int length, int width, int height, int mass) {
        bool isBulky = false,isHeavy = false;
        long long V = (long long)length * width * height;
        if(length >= pow(10,4) || width >= pow(10,4) || height >= pow(10,4) || V >= pow(10,9)) isBulky = true;
        if(mass >= 100) isHeavy = true;
        if(isBulky && isHeavy) return "Both";
        else if(!isBulky && !isHeavy) return "Neither";
        else if(isBulky && !isHeavy) return "Bulky";
        else return "Heavy";
    }
};
相关推荐
Funny_AI_LAB10 分钟前
MetaAI最新开源Llama3.2亮点及使用指南
算法·计算机视觉·语言模型·llama·facebook
NuyoahC17 分钟前
算法笔记(十一)——优先级队列(堆)
c++·笔记·算法·优先级队列
jk_10119 分钟前
MATLAB中decomposition函数用法
开发语言·算法·matlab
penguin_bark1 小时前
69. x 的平方根
算法
FL16238631291 小时前
[C++]使用纯opencv部署yolov11-pose姿态估计onnx模型
c++·opencv·yolo
sukalot1 小时前
windows C++-使用任务和 XML HTTP 请求进行连接(一)
c++·windows
一休哥助手1 小时前
Redis 五种数据类型及底层数据结构详解
数据结构·数据库·redis
这可就有点麻烦了1 小时前
强化学习笔记之【TD3算法】
linux·笔记·算法·机器学习
苏宸啊1 小时前
顺序表及其代码实现
数据结构·算法
lin zaixi()1 小时前
贪心思想之——最大子段和问题
数据结构·算法