#给你四个整数 length ,width ,height 和 mass
#分别表示一个箱子的三个维度和质量,请你返回一个表示箱子 类别 的字符串。
#如果满足以下条件,那么箱子是 "Bulky" 的:
#箱子 至少有一个 维度大于等于 104 。
#或者箱子的 体积 大于等于 109 。
#如果箱子的质量大于等于 100 ,那么箱子是 "Heavy" 的。
#如果箱子同时是 "Bulky" 和 "Heavy" ,那么返回类别为 "Both" 。
#如果箱子既不是 "Bulky" ,也不是 "Heavy" ,那么返回类别为 "Neither" 。
#如果箱子是 "Bulky" 但不是 "Heavy" ,那么返回类别为 "Bulky" 。
#如果箱子是 "Heavy" 但不是 "Bulky" ,那么返回类别为 "Heavy" 。
#注意,箱子的体积等于箱子的长度、宽度和高度的乘积。
class Solution(object):
def categorizeBox(self, length, width, height, mass):
"""
:type length: int
:type width: int
:type height: int
:type mass: int
:rtype: str
"""
x = 10
threshold1 = x**4
threshold2 = x**9
flag1 = ''
flag2 = ''
volume = length * height * width
if length >= threshold1 or width >= threshold1 or height >= threshold1 or volume >= threshold2:
flag1 = 'Bulky'
if mass >= 100:
flag2 = 'Heavy'
res = ''
if flag1 == 'Bulky' and flag2 == 'Heavy':
res = 'Both'
if flag1 != 'Bulky' and flag2 != 'Heavy':
res = 'Neither'
if flag1 == 'Bulky' and flag2 != 'Heavy':
res = 'Bulky'
if flag1 != 'Bulky' and flag2 == 'Heavy':
res = 'Heavy'
return res
leetcode 2525. 根据规则将箱子分类
于 2023-10-21 17:26:25 首次发布