LeetCode 2525: Categorize Box According to Criteria
Problem Description
Explanation:
- We need to categorize a box based on its dimensions and mass.
- We check if the box is "Bulky" or "Heavy" or both or neither according to the given conditions.
- We calculate the volume of the box and compare it with the threshold to determine if it is "Bulky".
- We check the mass of the box to determine if it is "Heavy".
- Finally, we combine the results to get the category of the box.
Time Complexity: O(1)
Space Complexity: O(1)
:
Solutions
class Solution {
public String categorizeBox(int length, int width, int height, int mass) {
if (length >= 104 || width >= 104 || height >= 104 || (long) length * width * height >= 1e9) {
if (mass >= 100) {
return "Both";
} else {
return "Bulky";
}
} else if (mass >= 100) {
return "Heavy";
} else {
return "Neither";
}
}
}
Loading editor...