• 【每日一题Day353】LC2525根据规则将箱子分类 | 模拟


    根据规则将箱子分类【LC2525】

    给你四个整数 lengthwidthheightmass ,分别表示一个箱子的三个维度和质量,请你返回一个表示箱子 类别字符串

    • 如果满足以下条件,那么箱子是

      "Bulky"
      
      • 1

      的:

      • 箱子 至少有一个 维度大于等于 104
      • 或者箱子的 体积 大于等于 109
    • 如果箱子的质量大于等于 100 ,那么箱子是 "Heavy" 的。

    • 如果箱子同时是 "Bulky""Heavy" ,那么返回类别为 "Both"

    • 如果箱子既不是 "Bulky" ,也不是 "Heavy" ,那么返回类别为 "Neither"

    • 如果箱子是 "Bulky" 但不是 "Heavy" ,那么返回类别为 "Bulky"

    • 如果箱子是 "Heavy" 但不是 "Bulky" ,那么返回类别为 "Heavy"

    注意,箱子的体积等于箱子的长度、宽度和高度的乘积。

    • 实现:变量标记

      class Solution {
          public String categorizeBox(int length, int width, int height, int mass) {
              boolean isBulky = false, isHeavy = false;
              long v = 1L * length * width * height;
              if (length >= 10000 || width >= 10000 || height >= 10000 || v >= 1e9){
                  isBulky = true;
              }
              if (mass >= 100){
                  isHeavy = true;
              }
              if (isBulky && isHeavy){
                  return "Both";
              }else if (isBulky){
                  return "Bulky";
              }else if (isHeavy){
                  return "Heavy";
              }else{
                  return "Neither";
              }
          }
      }
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
      • 15
      • 16
      • 17
      • 18
      • 19
      • 20
      • 21
      • 复杂度
        • 时间复杂度: O ( 1 ) \mathcal{O}(1) O(1)
        • 空间复杂度: O ( 1 ) \mathcal{O}(1) O(1)
    • 实现:数组标记

      class Solution {
          public String categorizeBox(int length, int width, int height, int mass) {
              int ans = 0;
              long v = 1L * length * width * height;
              if (length >= 10000 || width >= 10000 || height >= 10000 || v >= 1e9){
                  ans |= 1;
              }
              if (mass >= 100){
                  ans |= 2;
              }
              String[] ss = {"Neither", "Bulky", "Heavy", "Both"};
              return ss[ans];
          }
      }
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
      • 复杂度
        • 时间复杂度: O ( 1 ) \mathcal{O}(1) O(1)
        • 空间复杂度: O ( 1 ) \mathcal{O}(1) O(1)
  • 相关阅读:
    MyBatis详解
    奥特曼与钢铁侠【InsCode Stable Diffusion美图活动一期】
    《士兵突击》哪些最精彩的话语
    视频剪辑技巧:简单步骤,批量剪辑并随机分割视频
    最新Java JDK 21:全面解析与新特性探讨
    一个简单证件照的设计过程
    获得进程的内核转储core
    HTML超链接去下划线
    springboot银行客户管理系统毕业设计源码250903
    Redis安装到Windows系统上的详细步骤
  • 原文地址:https://blog.csdn.net/Tikitian/article/details/133947858