Skip to content

feat: add solutions to lc problem: No.10035 #2193

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

Merged
merged 1 commit into from
Jan 7, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,99 @@
<!-- 这里可写当前语言的特殊实现逻辑 -->

```python

class Solution:
def areaOfMaxDiagonal(self, dimensions: List[List[int]]) -> int:
ans = mx = 0
for l, w in dimensions:
t = l**2 + w**2
if mx < t:
mx = t
ans = l * w
elif mx == t:
ans = max(ans, l * w)
return ans
```

### **Java**

<!-- 这里可写当前语言的特殊实现逻辑 -->

```java

class Solution {
public int areaOfMaxDiagonal(int[][] dimensions) {
int ans = 0, mx = 0;
for (var d : dimensions) {
int l = d[0], w = d[1];
int t = l * l + w * w;
if (mx < t) {
mx = t;
ans = l * w;
} else if (mx == t) {
ans = Math.max(ans, l * w);
}
}
return ans;
}
}
```

### **C++**

```cpp

class Solution {
public:
int areaOfMaxDiagonal(vector<vector<int>>& dimensions) {
int ans = 0, mx = 0;
for (auto& d : dimensions) {
int l = d[0], w = d[1];
int t = l * l + w * w;
if (mx < t) {
mx = t;
ans = l * w;
} else if (mx == t) {
ans = max(ans, l * w);
}
}
return ans;
}
};
```

### **Go**

```go
func areaOfMaxDiagonal(dimensions [][]int) (ans int) {
mx := 0
for _, d := range dimensions {
l, w := d[0], d[1]
t := l*l + w*w
if mx < t {
mx = t
ans = l * w
} else if mx == t {
ans = max(ans, l*w)
}
}
return
}
```

### **TypeScript**

```ts
function areaOfMaxDiagonal(dimensions: number[][]): number {
let [ans, mx] = [0, 0];
for (const [l, w] of dimensions) {
const t = l * l + w * w;
if (mx < t) {
mx = t;
ans = l * w;
} else if (mx === t) {
ans = Math.max(ans, l * w);
}
}
return ans;
}
```

### **...**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,97 @@ So, the rectangle at index 1 has a greater diagonal length therefore we return a
### **Python3**

```python

class Solution:
def areaOfMaxDiagonal(self, dimensions: List[List[int]]) -> int:
ans = mx = 0
for l, w in dimensions:
t = l**2 + w**2
if mx < t:
mx = t
ans = l * w
elif mx == t:
ans = max(ans, l * w)
return ans
```

### **Java**

```java

class Solution {
public int areaOfMaxDiagonal(int[][] dimensions) {
int ans = 0, mx = 0;
for (var d : dimensions) {
int l = d[0], w = d[1];
int t = l * l + w * w;
if (mx < t) {
mx = t;
ans = l * w;
} else if (mx == t) {
ans = Math.max(ans, l * w);
}
}
return ans;
}
}
```

### **C++**

```cpp

class Solution {
public:
int areaOfMaxDiagonal(vector<vector<int>>& dimensions) {
int ans = 0, mx = 0;
for (auto& d : dimensions) {
int l = d[0], w = d[1];
int t = l * l + w * w;
if (mx < t) {
mx = t;
ans = l * w;
} else if (mx == t) {
ans = max(ans, l * w);
}
}
return ans;
}
};
```

### **Go**

```go
func areaOfMaxDiagonal(dimensions [][]int) (ans int) {
mx := 0
for _, d := range dimensions {
l, w := d[0], d[1]
t := l*l + w*w
if mx < t {
mx = t
ans = l * w
} else if mx == t {
ans = max(ans, l*w)
}
}
return
}
```

### **TypeScript**

```ts
function areaOfMaxDiagonal(dimensions: number[][]): number {
let [ans, mx] = [0, 0];
for (const [l, w] of dimensions) {
const t = l * l + w * w;
if (mx < t) {
mx = t;
ans = l * w;
} else if (mx === t) {
ans = Math.max(ans, l * w);
}
}
return ans;
}
```

### **...**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution {
public:
int areaOfMaxDiagonal(vector<vector<int>>& dimensions) {
int ans = 0, mx = 0;
for (auto& d : dimensions) {
int l = d[0], w = d[1];
int t = l * l + w * w;
if (mx < t) {
mx = t;
ans = l * w;
} else if (mx == t) {
ans = max(ans, l * w);
}
}
return ans;
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
func areaOfMaxDiagonal(dimensions [][]int) (ans int) {
mx := 0
for _, d := range dimensions {
l, w := d[0], d[1]
t := l*l + w*w
if mx < t {
mx = t
ans = l * w
} else if mx == t {
ans = max(ans, l*w)
}
}
return
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution {
public int areaOfMaxDiagonal(int[][] dimensions) {
int ans = 0, mx = 0;
for (var d : dimensions) {
int l = d[0], w = d[1];
int t = l * l + w * w;
if (mx < t) {
mx = t;
ans = l * w;
} else if (mx == t) {
ans = Math.max(ans, l * w);
}
}
return ans;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Solution:
def areaOfMaxDiagonal(self, dimensions: List[List[int]]) -> int:
ans = mx = 0
for l, w in dimensions:
t = l**2 + w**2
if mx < t:
mx = t
ans = l * w
elif mx == t:
ans = max(ans, l * w)
return ans
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function areaOfMaxDiagonal(dimensions: number[][]): number {
let [ans, mx] = [0, 0];
for (const [l, w] of dimensions) {
const t = l * l + w * w;
if (mx < t) {
mx = t;
ans = l * w;
} else if (mx === t) {
ans = Math.max(ans, l * w);
}
}
return ans;
}