Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6c09db4

Browse files
solves #2525: Categorize Box According to Criteria in java
1 parent e3c901c commit 6c09db4

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@
792792
| 2511 | [Maximum Enemy Forts That Can Be Captured](https://leetcode.com/problems/maximum-enemy-forts-that-can-be-captured) | [![Java](assets/java.png)](src/MaximumEnemyFortsThatCanBeCaptured.java) | |
793793
| 2515 | [Shortest Distance to Target String in a Circular Array](https://leetcode.com/problems/shortest-distance-to-target-string-in-a-circular-array) | [![Java](assets/java.png)](src/ShortestDistanceToTargetStringInACircularArray.java) | |
794794
| 2520 | [Count the Digits That Divide a Number](https://leetcode.com/problems/count-the-digits-that-divide-a-number) | [![Java](assets/java.png)](src/CountTheDigitsThatDivideANumber.java) | |
795-
| 2525 | [Categorize Box According to Criteria](https://leetcode.com/problems/categorize-box-according-to-criteria) | | |
795+
| 2525 | [Categorize Box According to Criteria](https://leetcode.com/problems/categorize-box-according-to-criteria) | [![Java](assets/java.png)](src/CategorizeBoxAccordingToCriteria.java) | |
796796
| 2529 | [Maximum Count of Positive Integer and Negative Integer](https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer) | | |
797797
| 2535 | [Difference Between Element Sum and Digit Sum of an Array](https://leetcode.com/problems/difference-between-element-sum-and-digit-sum-of-an-array) | | |
798798
| 2540 | [Minimum Common Value](https://leetcode.com/problems/minimum-common-value) | | |
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// https://leetcode.com/problems/categorize-box-according-to-criteria
2+
// T: O(1)
3+
// S: O(1)
4+
5+
public class CategorizeBoxAccordingToCriteria {
6+
public String categorizeBox(int length, int width, int height, int mass) {
7+
final boolean isBulky = isBulky(length, width, height, mass);
8+
final boolean isHeavy = mass >= 100;
9+
10+
if (isBulky && isHeavy) return "Both";
11+
if (!isBulky && !isHeavy) return "Neither";
12+
if (isBulky) return "Bulky";
13+
return "Heavy";
14+
}
15+
16+
private boolean isBulky(long length, long width, long height, long mass) {
17+
long volume = length * width * height;
18+
return length >= 10_000 || width >= 10_000 || height >= 10_000 || mass >= 10_000 || volume >= 1_000_000_000;
19+
}
20+
}

0 commit comments

Comments
 (0)