Skip to content

Commit 0a52fd5

Browse files
committed
960
1 parent baa236e commit 0a52fd5

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

leetcode/960/0.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["babbba","bbaaab"]

leetcode/960/main.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
3+
*/
4+
5+
#include <bits/stdc++.h>
6+
#include "../../lib/LeetCodeInput.hpp"
7+
#include "solution.cpp"
8+
using namespace std;
9+
10+
int main()
11+
{
12+
LeetCodeInput li("0.in");
13+
14+
// vector<vector<int>> mat_1 = li.get_vvi(0);
15+
// vector<int> arr_1 = li.get_vi(0);
16+
// int num_1 = li.get_i(0);
17+
// string s_1 = li.get_s(0);
18+
vector<string> arr_1 = li.get_vs(0);
19+
20+
chrono::steady_clock::time_point begin = chrono::steady_clock::now();
21+
Solution solution;
22+
auto output = solution.minDeletionSize(arr_1);
23+
chrono::steady_clock::time_point end = chrono::steady_clock::now();
24+
cout << "Time difference = " << chrono::duration_cast<chrono::microseconds> (end - begin).count() << "µs" << endl;
25+
26+
cout << output << endl;
27+
28+
// for (int i: output){
29+
// cout << i << ' ';
30+
// }
31+
32+
// for (auto i: output){
33+
// for (int j: i){
34+
// cout << j << ' ';
35+
// }
36+
// cout << '\n';
37+
// }
38+
39+
return 0;
40+
}

leetcode/960/solution.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
3+
time: O(nm^2)
4+
space: O(m)
5+
6+
Runtime: 10 ms, faster than 100.00% of C++ online submissions for Delete Columns to Make Sorted III.
7+
Memory Usage: 10.3 MB, less than 51.49% of C++ online submissions for Delete Columns to Make Sorted III.
8+
*/
9+
10+
#include <bits/stdc++.h>
11+
12+
using namespace std;
13+
14+
#define all(x) begin(x), end(x)
15+
typedef vector<int> vi;
16+
typedef vector<vector<int>> vvi;
17+
18+
class Solution {
19+
public:
20+
int dp[100];
21+
int minDeletionSize(vector<string>& strs) {
22+
int n = size(strs);
23+
int m = size(strs[0]);
24+
fill_n(dp, m, 1);
25+
int k;
26+
int dp_max = 0;
27+
for (int i=0; i<m; ++i){
28+
for (int j=i+1; j<m; ++j){
29+
for (k=0; k<n; ++k){
30+
if (strs[k][i]>strs[k][j]){
31+
break;
32+
}
33+
}
34+
if (k==n){
35+
dp[j]=max(dp[j],dp[i]+1);
36+
}
37+
}
38+
dp_max = max(dp_max, dp[i]);
39+
}
40+
return m-dp_max;
41+
}
42+
};
43+
44+
const static auto initialize = [] {
45+
std::ios::sync_with_stdio(false);
46+
std::cin.tie(nullptr);
47+
std::cout.tie(nullptr);
48+
return nullptr;
49+
}();

0 commit comments

Comments
 (0)