File tree Expand file tree Collapse file tree 3 files changed +90
-0
lines changed
Expand file tree Collapse file tree 3 files changed +90
-0
lines changed Original file line number Diff line number Diff line change 1+ ["babbba","bbaaab"]
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }();
You can’t perform that action at this time.
0 commit comments