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

Commit 16b4ce4

Browse files
authored
feat: add solutions to lc problem: No.10035 (doocs#2193)
No.10035.Maximum Area of Longest Diagonal Rectangle
1 parent d668513 commit 16b4ce4

File tree

7 files changed

+221
-6
lines changed

7 files changed

+221
-6
lines changed

solution/10000-10099/10035.Maximum Area of Longest Diagonal Rectangle/README.md

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,99 @@
5454
<!-- 这里可写当前语言的特殊实现逻辑 -->
5555

5656
```python
57-
57+
class Solution:
58+
def areaOfMaxDiagonal(self, dimensions: List[List[int]]) -> int:
59+
ans = mx = 0
60+
for l, w in dimensions:
61+
t = l**2 + w**2
62+
if mx < t:
63+
mx = t
64+
ans = l * w
65+
elif mx == t:
66+
ans = max(ans, l * w)
67+
return ans
5868
```
5969

6070
### **Java**
6171

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

6474
```java
65-
75+
class Solution {
76+
public int areaOfMaxDiagonal(int[][] dimensions) {
77+
int ans = 0, mx = 0;
78+
for (var d : dimensions) {
79+
int l = d[0], w = d[1];
80+
int t = l * l + w * w;
81+
if (mx < t) {
82+
mx = t;
83+
ans = l * w;
84+
} else if (mx == t) {
85+
ans = Math.max(ans, l * w);
86+
}
87+
}
88+
return ans;
89+
}
90+
}
6691
```
6792

6893
### **C++**
6994

7095
```cpp
71-
96+
class Solution {
97+
public:
98+
int areaOfMaxDiagonal(vector<vector<int>>& dimensions) {
99+
int ans = 0, mx = 0;
100+
for (auto& d : dimensions) {
101+
int l = d[0], w = d[1];
102+
int t = l * l + w * w;
103+
if (mx < t) {
104+
mx = t;
105+
ans = l * w;
106+
} else if (mx == t) {
107+
ans = max(ans, l * w);
108+
}
109+
}
110+
return ans;
111+
}
112+
};
72113
```
73114
74115
### **Go**
75116
76117
```go
118+
func areaOfMaxDiagonal(dimensions [][]int) (ans int) {
119+
mx := 0
120+
for _, d := range dimensions {
121+
l, w := d[0], d[1]
122+
t := l*l + w*w
123+
if mx < t {
124+
mx = t
125+
ans = l * w
126+
} else if mx == t {
127+
ans = max(ans, l*w)
128+
}
129+
}
130+
return
131+
}
132+
```
77133

134+
### **TypeScript**
135+
136+
```ts
137+
function areaOfMaxDiagonal(dimensions: number[][]): number {
138+
let [ans, mx] = [0, 0];
139+
for (const [l, w] of dimensions) {
140+
const t = l * l + w * w;
141+
if (mx < t) {
142+
mx = t;
143+
ans = l * w;
144+
} else if (mx === t) {
145+
ans = Math.max(ans, l * w);
146+
}
147+
}
148+
return ans;
149+
}
78150
```
79151

80152
### **...**

solution/10000-10099/10035.Maximum Area of Longest Diagonal Rectangle/README_EN.md

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,97 @@ So, the rectangle at index 1 has a greater diagonal length therefore we return a
4646
### **Python3**
4747

4848
```python
49-
49+
class Solution:
50+
def areaOfMaxDiagonal(self, dimensions: List[List[int]]) -> int:
51+
ans = mx = 0
52+
for l, w in dimensions:
53+
t = l**2 + w**2
54+
if mx < t:
55+
mx = t
56+
ans = l * w
57+
elif mx == t:
58+
ans = max(ans, l * w)
59+
return ans
5060
```
5161

5262
### **Java**
5363

5464
```java
55-
65+
class Solution {
66+
public int areaOfMaxDiagonal(int[][] dimensions) {
67+
int ans = 0, mx = 0;
68+
for (var d : dimensions) {
69+
int l = d[0], w = d[1];
70+
int t = l * l + w * w;
71+
if (mx < t) {
72+
mx = t;
73+
ans = l * w;
74+
} else if (mx == t) {
75+
ans = Math.max(ans, l * w);
76+
}
77+
}
78+
return ans;
79+
}
80+
}
5681
```
5782

5883
### **C++**
5984

6085
```cpp
61-
86+
class Solution {
87+
public:
88+
int areaOfMaxDiagonal(vector<vector<int>>& dimensions) {
89+
int ans = 0, mx = 0;
90+
for (auto& d : dimensions) {
91+
int l = d[0], w = d[1];
92+
int t = l * l + w * w;
93+
if (mx < t) {
94+
mx = t;
95+
ans = l * w;
96+
} else if (mx == t) {
97+
ans = max(ans, l * w);
98+
}
99+
}
100+
return ans;
101+
}
102+
};
62103
```
63104
64105
### **Go**
65106
66107
```go
108+
func areaOfMaxDiagonal(dimensions [][]int) (ans int) {
109+
mx := 0
110+
for _, d := range dimensions {
111+
l, w := d[0], d[1]
112+
t := l*l + w*w
113+
if mx < t {
114+
mx = t
115+
ans = l * w
116+
} else if mx == t {
117+
ans = max(ans, l*w)
118+
}
119+
}
120+
return
121+
}
122+
```
67123

124+
### **TypeScript**
125+
126+
```ts
127+
function areaOfMaxDiagonal(dimensions: number[][]): number {
128+
let [ans, mx] = [0, 0];
129+
for (const [l, w] of dimensions) {
130+
const t = l * l + w * w;
131+
if (mx < t) {
132+
mx = t;
133+
ans = l * w;
134+
} else if (mx === t) {
135+
ans = Math.max(ans, l * w);
136+
}
137+
}
138+
return ans;
139+
}
68140
```
69141

70142
### **...**
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
int areaOfMaxDiagonal(vector<vector<int>>& dimensions) {
4+
int ans = 0, mx = 0;
5+
for (auto& d : dimensions) {
6+
int l = d[0], w = d[1];
7+
int t = l * l + w * w;
8+
if (mx < t) {
9+
mx = t;
10+
ans = l * w;
11+
} else if (mx == t) {
12+
ans = max(ans, l * w);
13+
}
14+
}
15+
return ans;
16+
}
17+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
func areaOfMaxDiagonal(dimensions [][]int) (ans int) {
2+
mx := 0
3+
for _, d := range dimensions {
4+
l, w := d[0], d[1]
5+
t := l*l + w*w
6+
if mx < t {
7+
mx = t
8+
ans = l * w
9+
} else if mx == t {
10+
ans = max(ans, l*w)
11+
}
12+
}
13+
return
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public int areaOfMaxDiagonal(int[][] dimensions) {
3+
int ans = 0, mx = 0;
4+
for (var d : dimensions) {
5+
int l = d[0], w = d[1];
6+
int t = l * l + w * w;
7+
if (mx < t) {
8+
mx = t;
9+
ans = l * w;
10+
} else if (mx == t) {
11+
ans = Math.max(ans, l * w);
12+
}
13+
}
14+
return ans;
15+
}
16+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
def areaOfMaxDiagonal(self, dimensions: List[List[int]]) -> int:
3+
ans = mx = 0
4+
for l, w in dimensions:
5+
t = l**2 + w**2
6+
if mx < t:
7+
mx = t
8+
ans = l * w
9+
elif mx == t:
10+
ans = max(ans, l * w)
11+
return ans
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function areaOfMaxDiagonal(dimensions: number[][]): number {
2+
let [ans, mx] = [0, 0];
3+
for (const [l, w] of dimensions) {
4+
const t = l * l + w * w;
5+
if (mx < t) {
6+
mx = t;
7+
ans = l * w;
8+
} else if (mx === t) {
9+
ans = Math.max(ans, l * w);
10+
}
11+
}
12+
return ans;
13+
}

0 commit comments

Comments
 (0)