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";
    }
};
相关推荐
三毛的二哥3 小时前
BEV:典型BEV算法总结
人工智能·算法·计算机视觉·3d
南宫萧幕4 小时前
自控PID+MATLAB仿真+混动P0/P1/P2/P3/P4构型
算法·机器学习·matlab·simulink·控制·pid
浪浪小洋5 小时前
c++ qt课设定制
开发语言·c++
charlie1145141915 小时前
嵌入式C++工程实践第16篇:第四次重构 —— LED模板,从通用GPIO到专用抽象
c语言·开发语言·c++·驱动开发·嵌入式硬件·重构
handler015 小时前
Linux: 基本指令知识点(2)
linux·服务器·c语言·c++·笔记·学习
故事和你915 小时前
洛谷-数据结构1-4-图的基本应用1
开发语言·数据结构·算法·深度优先·动态规划·图论
我叫黑大帅5 小时前
为什么map查找时间复杂度是O(1)?
后端·算法·面试
炽烈小老头5 小时前
【每天学习一点算法 2026/04/20】除自身以外数组的乘积
学习·算法
skilllite作者6 小时前
AI agent 的 Assistant Auto LLM Routing 规划的思考
网络·人工智能·算法·rust·openclaw·agentskills
破浪前行·吴7 小时前
数据结构概述
数据结构·学习