-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add solutions to lc problem: No.10035 (#2193)
No.10035.Maximum Area of Longest Diagonal Rectangle
- Loading branch information
Showing
7 changed files
with
221 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
solution/10000-10099/10035.Maximum Area of Longest Diagonal Rectangle/Solution.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; |
14 changes: 14 additions & 0 deletions
14
solution/10000-10099/10035.Maximum Area of Longest Diagonal Rectangle/Solution.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
16 changes: 16 additions & 0 deletions
16
solution/10000-10099/10035.Maximum Area of Longest Diagonal Rectangle/Solution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
solution/10000-10099/10035.Maximum Area of Longest Diagonal Rectangle/Solution.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
13 changes: 13 additions & 0 deletions
13
solution/10000-10099/10035.Maximum Area of Longest Diagonal Rectangle/Solution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |