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 problems: No.1691,1699 #2299

Merged
merged 2 commits into from
Feb 2, 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 @@ -128,7 +128,9 @@ class Solution {
class Solution {
public:
int maxHeight(vector<vector<int>>& cuboids) {
for (auto& c : cuboids) sort(c.begin(), c.end());
for (auto& c : cuboids) {
sort(c.begin(), c.end());
}
sort(cuboids.begin(), cuboids.end());
int n = cuboids.size();
vector<int> f(n);
Expand Down Expand Up @@ -168,6 +170,33 @@ func maxHeight(cuboids [][]int) int {
}
```

```ts
function maxHeight(cuboids: number[][]): number {
for (const c of cuboids) {
c.sort((a, b) => a - b);
}
cuboids.sort((a, b) => {
if (a[0] !== b[0]) {
return a[0] - b[0];
}
if (a[1] !== b[1]) {
return a[1] - b[1];
}
return a[2] - b[2];
});
const n = cuboids.length;
const f = Array(n).fill(0);
for (let i = 0; i < n; ++i) {
for (let j = 0; j < i; ++j) {
const ok = cuboids[j][1] <= cuboids[i][1] && cuboids[j][2] <= cuboids[i][2];
if (ok) f[i] = Math.max(f[i], f[j]);
}
f[i] += cuboids[i][2];
}
return Math.max(...f);
}
```

```js
/**
* @param {number[][]} cuboids
Expand All @@ -178,12 +207,16 @@ var maxHeight = function (cuboids) {
c.sort((a, b) => a - b);
}
cuboids.sort((a, b) => {
if (a[0] != b[0]) return a[0] - b[0];
if (a[1] != b[1]) return a[1] - b[1];
if (a[0] !== b[0]) {
return a[0] - b[0];
}
if (a[1] !== b[1]) {
return a[1] - b[1];
}
return a[2] - b[2];
});
const n = cuboids.length;
const f = new Array(n).fill(0);
const f = Array(n).fill(0);
for (let i = 0; i < n; ++i) {
for (let j = 0; j < i; ++j) {
const ok = cuboids[j][1] <= cuboids[i][1] && cuboids[j][2] <= cuboids[i][2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ class Solution {
class Solution {
public:
int maxHeight(vector<vector<int>>& cuboids) {
for (auto& c : cuboids) sort(c.begin(), c.end());
for (auto& c : cuboids) {
sort(c.begin(), c.end());
}
sort(cuboids.begin(), cuboids.end());
int n = cuboids.size();
vector<int> f(n);
Expand Down Expand Up @@ -164,6 +166,33 @@ func maxHeight(cuboids [][]int) int {
}
```

```ts
function maxHeight(cuboids: number[][]): number {
for (const c of cuboids) {
c.sort((a, b) => a - b);
}
cuboids.sort((a, b) => {
if (a[0] !== b[0]) {
return a[0] - b[0];
}
if (a[1] !== b[1]) {
return a[1] - b[1];
}
return a[2] - b[2];
});
const n = cuboids.length;
const f = Array(n).fill(0);
for (let i = 0; i < n; ++i) {
for (let j = 0; j < i; ++j) {
const ok = cuboids[j][1] <= cuboids[i][1] && cuboids[j][2] <= cuboids[i][2];
if (ok) f[i] = Math.max(f[i], f[j]);
}
f[i] += cuboids[i][2];
}
return Math.max(...f);
}
```

```js
/**
* @param {number[][]} cuboids
Expand All @@ -174,12 +203,16 @@ var maxHeight = function (cuboids) {
c.sort((a, b) => a - b);
}
cuboids.sort((a, b) => {
if (a[0] != b[0]) return a[0] - b[0];
if (a[1] != b[1]) return a[1] - b[1];
if (a[0] !== b[0]) {
return a[0] - b[0];
}
if (a[1] !== b[1]) {
return a[1] - b[1];
}
return a[2] - b[2];
});
const n = cuboids.length;
const f = new Array(n).fill(0);
const f = Array(n).fill(0);
for (let i = 0; i < n; ++i) {
for (let j = 0; j < i; ++j) {
const ok = cuboids[j][1] <= cuboids[i][1] && cuboids[j][2] <= cuboids[i][2];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
class Solution {
public:
int maxHeight(vector<vector<int>>& cuboids) {
for (auto& c : cuboids) sort(c.begin(), c.end());
for (auto& c : cuboids) {
sort(c.begin(), c.end());
}
sort(cuboids.begin(), cuboids.end());
int n = cuboids.size();
vector<int> f(n);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ var maxHeight = function (cuboids) {
c.sort((a, b) => a - b);
}
cuboids.sort((a, b) => {
if (a[0] != b[0]) return a[0] - b[0];
if (a[1] != b[1]) return a[1] - b[1];
if (a[0] !== b[0]) {
return a[0] - b[0];
}
if (a[1] !== b[1]) {
return a[1] - b[1];
}
return a[2] - b[2];
});
const n = cuboids.length;
const f = new Array(n).fill(0);
const f = Array(n).fill(0);
for (let i = 0; i < n; ++i) {
for (let j = 0; j < i; ++j) {
const ok = cuboids[j][1] <= cuboids[i][1] && cuboids[j][2] <= cuboids[i][2];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function maxHeight(cuboids: number[][]): number {
for (const c of cuboids) {
c.sort((a, b) => a - b);
}
cuboids.sort((a, b) => {
if (a[0] !== b[0]) {
return a[0] - b[0];
}
if (a[1] !== b[1]) {
return a[1] - b[1];
}
return a[2] - b[2];
});
const n = cuboids.length;
const f = Array(n).fill(0);
for (let i = 0; i < n; ++i) {
for (let j = 0; j < i; ++j) {
const ok = cuboids[j][1] <= cuboids[i][1] && cuboids[j][2] <= cuboids[i][2];
if (ok) f[i] = Math.max(f[i], f[j]);
}
f[i] += cuboids[i][2];
}
return Math.max(...f);
}
Loading