Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add solutions to lc problem: No.2525 #1851

Merged
merged 4 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions solution/2500-2599/2525.Categorize Box According to Criteria/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,23 @@ class Solution:
return d[i]
```

```python
class Solution:
def categorizeBox(self, length: int, width: int, height: int, mass: int) -> str:
v = length * width * height
bulky = any(x >= 10000 for x in (length, width, height)) or v >= 10**9
heavy = mass >= 100

if bulky and heavy:
return "Both"
if bulky:
return "Bulky"
if heavy:
return "Heavy"

return "Neither"
```

### **Java**

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

```java
class Solution {
public String categorizeBox(int length, int width, int height, int mass) {
long v = (long) length * width * height;
boolean bulky = length >= 1e4 || width >= 1e4 || height >= 1e4 || v >= 1e9;
boolean heavy = mass >= 100;

if (bulky && heavy) {
return "Both";
}
if (bulky) {
return "Bulky";
}
if (heavy) {
return "Heavy";
}

return "Neither";
}
}
```

### **C++**

```cpp
Expand All @@ -117,6 +156,29 @@ public:
};
```

```cpp
class Solution {
public:
string categorizeBox(int length, int width, int height, int mass) {
long v = (long) length * width * height;
bool bulky = length >= 1e4 || width >= 1e4 || height >= 1e4 || v >= 1e9;
bool heavy = mass >= 100;

if (bulky && heavy) {
return "Both";
}
if (bulky) {
return "Bulky";
}
if (heavy) {
return "Heavy";
}

return "Neither";
}
};
```

### **Go**

```go
Expand All @@ -134,6 +196,24 @@ func categorizeBox(length int, width int, height int, mass int) string {
}
```

```go
func categorizeBox(length int, width int, height int, mass int) string {
v := length * width * height
bulky := length >= 1e4 || width >= 1e4 || height >= 1e4 || v >= 1e9
heavy := mass >= 100
if bulky && heavy {
return "Both"
}
if bulky {
return "Bulky"
}
if heavy {
return "Heavy"
}
return "Neither"
}
```

### **TypeScript**

```ts
Expand All @@ -150,6 +230,24 @@ function categorizeBox(length: number, width: number, height: number, mass: numb
}
```

```ts
function categorizeBox(length: number, width: number, height: number, mass: number): string {
const v = length * width * height;
const bulky = length >= 1e4 || width >= 1e4 || height >= 1e4 || v >= 1e9;
const heavy = mass >= 100;
if (bulky && heavy) {
return 'Both';
}
if (bulky) {
return 'Bulky';
}
if (heavy) {
return 'Heavy';
}
return 'Neither';
}
```

### **Rust**

```rust
Expand All @@ -172,6 +270,29 @@ impl Solution {
}
```

```rust
impl Solution {
pub fn categorize_box(length: i32, width: i32, height: i32, mass: i32) -> String {
let v = length * width * height;
let bulky = length >= 10000 || width >= 10000 || height >= 10000 || length as i64 * width as i64 * height as i64 >= 1000000000;

let heavy = mass >= 100;

if bulky && heavy {
return "Both".to_string();
}
if bulky {
return "Bulky".to_string();
}
if heavy {
return "Heavy".to_string();
}

"Neither".to_string()
}
}
```

### **...**

```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ Since its neither of the two above categories, we return &quot;Neither&quot;.</p

## Solutions

**Solution 1: Simulation**

We can simulate according to the problem description.

The time complexity is $O(1)$, and the space complexity is $O(1)$.

<!-- tabs:start -->

### **Python3**
Expand All @@ -70,6 +76,23 @@ class Solution:
return d[i]
```

```python
class Solution:
def categorizeBox(self, length: int, width: int, height: int, mass: int) -> str:
v = length * width * height
bulky = any(x >= 10000 for x in (length, width, height)) or v >= 10**9
heavy = mass >= 100

if bulky and heavy:
return "Both"
if bulky:
return "Bulky"
if heavy:
return "Heavy"

return "Neither"
```

### **Java**

```java
Expand All @@ -85,6 +108,28 @@ class Solution {
}
```

```java
class Solution {
public String categorizeBox(int length, int width, int height, int mass) {
long v = (long) length * width * height;
boolean bulky = length >= 1e4 || width >= 1e4 || height >= 1e4 || v >= 1e9;
boolean heavy = mass >= 100;

if (bulky && heavy) {
return "Both";
}
if (bulky) {
return "Bulky";
}
if (heavy) {
return "Heavy";
}

return "Neither";
}
}
```

### **C++**

```cpp
Expand All @@ -101,6 +146,29 @@ public:
};
```

```cpp
class Solution {
public:
string categorizeBox(int length, int width, int height, int mass) {
long v = (long) length * width * height;
bool bulky = length >= 1e4 || width >= 1e4 || height >= 1e4 || v >= 1e9;
bool heavy = mass >= 100;

if (bulky && heavy) {
return "Both";
}
if (bulky) {
return "Bulky";
}
if (heavy) {
return "Heavy";
}

return "Neither";
}
};
```

### **Go**

```go
Expand All @@ -118,6 +186,24 @@ func categorizeBox(length int, width int, height int, mass int) string {
}
```

```go
func categorizeBox(length int, width int, height int, mass int) string {
v := length * width * height
bulky := length >= 1e4 || width >= 1e4 || height >= 1e4 || v >= 1e9
heavy := mass >= 100
if bulky && heavy {
return "Both"
}
if bulky {
return "Bulky"
}
if heavy {
return "Heavy"
}
return "Neither"
}
```

### **TypeScript**

```ts
Expand All @@ -134,6 +220,24 @@ function categorizeBox(length: number, width: number, height: number, mass: numb
}
```

```ts
function categorizeBox(length: number, width: number, height: number, mass: number): string {
const v = length * width * height;
const bulky = length >= 1e4 || width >= 1e4 || height >= 1e4 || v >= 1e9;
const heavy = mass >= 100;
if (bulky && heavy) {
return 'Both';
}
if (bulky) {
return 'Bulky';
}
if (heavy) {
return 'Heavy';
}
return 'Neither';
}
```

### **Rust**

```rust
Expand All @@ -156,6 +260,29 @@ impl Solution {
}
```

```rust
impl Solution {
pub fn categorize_box(length: i32, width: i32, height: i32, mass: i32) -> String {
let v = length * width * height;
let bulky = length >= 10000 || width >= 10000 || height >= 10000 || length as i64 * width as i64 * height as i64 >= 1000000000;

let heavy = mass >= 100;

if bulky && heavy {
return "Both".to_string();
}
if bulky {
return "Bulky".to_string();
}
if heavy {
return "Heavy".to_string();
}

"Neither".to_string()
}
}
```

### **...**

```
Expand Down