Skip to content

Commit

Permalink
feat: add solutions to lc problem: No.10035 (#2193)
Browse files Browse the repository at this point in the history
No.10035.Maximum Area of Longest Diagonal Rectangle
  • Loading branch information
yanglbme authored Jan 7, 2024
1 parent d668513 commit 16b4ce4
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 6 deletions.
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;
}

0 comments on commit 16b4ce4

Please sign in to comment.