Skip to content

Commit 6bf70ed

Browse files
authored
feat: add solutions to lc problem: No.2525 (#1851)
1 parent c198d59 commit 6bf70ed

File tree

2 files changed

+248
-0
lines changed

2 files changed

+248
-0
lines changed

solution/2500-2599/2525.Categorize Box According to Criteria/README.md

+121
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,23 @@ class Solution:
8484
return d[i]
8585
```
8686

87+
```python
88+
class Solution:
89+
def categorizeBox(self, length: int, width: int, height: int, mass: int) -> str:
90+
v = length * width * height
91+
bulky = any(x >= 10000 for x in (length, width, height)) or v >= 10**9
92+
heavy = mass >= 100
93+
94+
if bulky and heavy:
95+
return "Both"
96+
if bulky:
97+
return "Bulky"
98+
if heavy:
99+
return "Heavy"
100+
101+
return "Neither"
102+
```
103+
87104
### **Java**
88105

89106
<!-- 这里可写当前语言的特殊实现逻辑 -->
@@ -101,6 +118,28 @@ class Solution {
101118
}
102119
```
103120

121+
```java
122+
class Solution {
123+
public String categorizeBox(int length, int width, int height, int mass) {
124+
long v = (long) length * width * height;
125+
boolean bulky = length >= 1e4 || width >= 1e4 || height >= 1e4 || v >= 1e9;
126+
boolean heavy = mass >= 100;
127+
128+
if (bulky && heavy) {
129+
return "Both";
130+
}
131+
if (bulky) {
132+
return "Bulky";
133+
}
134+
if (heavy) {
135+
return "Heavy";
136+
}
137+
138+
return "Neither";
139+
}
140+
}
141+
```
142+
104143
### **C++**
105144

106145
```cpp
@@ -117,6 +156,29 @@ public:
117156
};
118157
```
119158
159+
```cpp
160+
class Solution {
161+
public:
162+
string categorizeBox(int length, int width, int height, int mass) {
163+
long v = (long) length * width * height;
164+
bool bulky = length >= 1e4 || width >= 1e4 || height >= 1e4 || v >= 1e9;
165+
bool heavy = mass >= 100;
166+
167+
if (bulky && heavy) {
168+
return "Both";
169+
}
170+
if (bulky) {
171+
return "Bulky";
172+
}
173+
if (heavy) {
174+
return "Heavy";
175+
}
176+
177+
return "Neither";
178+
}
179+
};
180+
```
181+
120182
### **Go**
121183

122184
```go
@@ -134,6 +196,24 @@ func categorizeBox(length int, width int, height int, mass int) string {
134196
}
135197
```
136198

199+
```go
200+
func categorizeBox(length int, width int, height int, mass int) string {
201+
v := length * width * height
202+
bulky := length >= 1e4 || width >= 1e4 || height >= 1e4 || v >= 1e9
203+
heavy := mass >= 100
204+
if bulky && heavy {
205+
return "Both"
206+
}
207+
if bulky {
208+
return "Bulky"
209+
}
210+
if heavy {
211+
return "Heavy"
212+
}
213+
return "Neither"
214+
}
215+
```
216+
137217
### **TypeScript**
138218

139219
```ts
@@ -150,6 +230,24 @@ function categorizeBox(length: number, width: number, height: number, mass: numb
150230
}
151231
```
152232

233+
```ts
234+
function categorizeBox(length: number, width: number, height: number, mass: number): string {
235+
const v = length * width * height;
236+
const bulky = length >= 1e4 || width >= 1e4 || height >= 1e4 || v >= 1e9;
237+
const heavy = mass >= 100;
238+
if (bulky && heavy) {
239+
return 'Both';
240+
}
241+
if (bulky) {
242+
return 'Bulky';
243+
}
244+
if (heavy) {
245+
return 'Heavy';
246+
}
247+
return 'Neither';
248+
}
249+
```
250+
153251
### **Rust**
154252

155253
```rust
@@ -172,6 +270,29 @@ impl Solution {
172270
}
173271
```
174272

273+
```rust
274+
impl Solution {
275+
pub fn categorize_box(length: i32, width: i32, height: i32, mass: i32) -> String {
276+
let v = length * width * height;
277+
let bulky = length >= 10000 || width >= 10000 || height >= 10000 || length as i64 * width as i64 * height as i64 >= 1000000000;
278+
279+
let heavy = mass >= 100;
280+
281+
if bulky && heavy {
282+
return "Both".to_string();
283+
}
284+
if bulky {
285+
return "Bulky".to_string();
286+
}
287+
if heavy {
288+
return "Heavy".to_string();
289+
}
290+
291+
"Neither".to_string()
292+
}
293+
}
294+
```
295+
175296
### **...**
176297

177298
```

solution/2500-2599/2525.Categorize Box According to Criteria/README_EN.md

+127
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ Since its neither of the two above categories, we return &quot;Neither&quot;.</p
5555

5656
## Solutions
5757

58+
**Solution 1: Simulation**
59+
60+
We can simulate according to the problem description.
61+
62+
The time complexity is $O(1)$, and the space complexity is $O(1)$.
63+
5864
<!-- tabs:start -->
5965

6066
### **Python3**
@@ -70,6 +76,23 @@ class Solution:
7076
return d[i]
7177
```
7278

79+
```python
80+
class Solution:
81+
def categorizeBox(self, length: int, width: int, height: int, mass: int) -> str:
82+
v = length * width * height
83+
bulky = any(x >= 10000 for x in (length, width, height)) or v >= 10**9
84+
heavy = mass >= 100
85+
86+
if bulky and heavy:
87+
return "Both"
88+
if bulky:
89+
return "Bulky"
90+
if heavy:
91+
return "Heavy"
92+
93+
return "Neither"
94+
```
95+
7396
### **Java**
7497

7598
```java
@@ -85,6 +108,28 @@ class Solution {
85108
}
86109
```
87110

111+
```java
112+
class Solution {
113+
public String categorizeBox(int length, int width, int height, int mass) {
114+
long v = (long) length * width * height;
115+
boolean bulky = length >= 1e4 || width >= 1e4 || height >= 1e4 || v >= 1e9;
116+
boolean heavy = mass >= 100;
117+
118+
if (bulky && heavy) {
119+
return "Both";
120+
}
121+
if (bulky) {
122+
return "Bulky";
123+
}
124+
if (heavy) {
125+
return "Heavy";
126+
}
127+
128+
return "Neither";
129+
}
130+
}
131+
```
132+
88133
### **C++**
89134

90135
```cpp
@@ -101,6 +146,29 @@ public:
101146
};
102147
```
103148
149+
```cpp
150+
class Solution {
151+
public:
152+
string categorizeBox(int length, int width, int height, int mass) {
153+
long v = (long) length * width * height;
154+
bool bulky = length >= 1e4 || width >= 1e4 || height >= 1e4 || v >= 1e9;
155+
bool heavy = mass >= 100;
156+
157+
if (bulky && heavy) {
158+
return "Both";
159+
}
160+
if (bulky) {
161+
return "Bulky";
162+
}
163+
if (heavy) {
164+
return "Heavy";
165+
}
166+
167+
return "Neither";
168+
}
169+
};
170+
```
171+
104172
### **Go**
105173

106174
```go
@@ -118,6 +186,24 @@ func categorizeBox(length int, width int, height int, mass int) string {
118186
}
119187
```
120188

189+
```go
190+
func categorizeBox(length int, width int, height int, mass int) string {
191+
v := length * width * height
192+
bulky := length >= 1e4 || width >= 1e4 || height >= 1e4 || v >= 1e9
193+
heavy := mass >= 100
194+
if bulky && heavy {
195+
return "Both"
196+
}
197+
if bulky {
198+
return "Bulky"
199+
}
200+
if heavy {
201+
return "Heavy"
202+
}
203+
return "Neither"
204+
}
205+
```
206+
121207
### **TypeScript**
122208

123209
```ts
@@ -134,6 +220,24 @@ function categorizeBox(length: number, width: number, height: number, mass: numb
134220
}
135221
```
136222

223+
```ts
224+
function categorizeBox(length: number, width: number, height: number, mass: number): string {
225+
const v = length * width * height;
226+
const bulky = length >= 1e4 || width >= 1e4 || height >= 1e4 || v >= 1e9;
227+
const heavy = mass >= 100;
228+
if (bulky && heavy) {
229+
return 'Both';
230+
}
231+
if (bulky) {
232+
return 'Bulky';
233+
}
234+
if (heavy) {
235+
return 'Heavy';
236+
}
237+
return 'Neither';
238+
}
239+
```
240+
137241
### **Rust**
138242

139243
```rust
@@ -156,6 +260,29 @@ impl Solution {
156260
}
157261
```
158262

263+
```rust
264+
impl Solution {
265+
pub fn categorize_box(length: i32, width: i32, height: i32, mass: i32) -> String {
266+
let v = length * width * height;
267+
let bulky = length >= 10000 || width >= 10000 || height >= 10000 || length as i64 * width as i64 * height as i64 >= 1000000000;
268+
269+
let heavy = mass >= 100;
270+
271+
if bulky && heavy {
272+
return "Both".to_string();
273+
}
274+
if bulky {
275+
return "Bulky".to_string();
276+
}
277+
if heavy {
278+
return "Heavy".to_string();
279+
}
280+
281+
"Neither".to_string()
282+
}
283+
}
284+
```
285+
159286
### **...**
160287

161288
```

0 commit comments

Comments
 (0)