diff options
Diffstat (limited to 'other/delete_col_sorted.cpp')
-rw-r--r-- | other/delete_col_sorted.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/other/delete_col_sorted.cpp b/other/delete_col_sorted.cpp new file mode 100644 index 0000000..4954032 --- /dev/null +++ b/other/delete_col_sorted.cpp @@ -0,0 +1,26 @@ +#include "leetcode.h" + +class Solution { +public: + int minDeletionSize(vector<string> &strs) { + int ans = 0; + if (strs.empty()) + return ans; + for (auto i = 0; i < strs[0].size(); ++i) + for (auto j = 1; j < strs.size(); ++j) + if (strs[j - 1][i] > strs[j][i]) { + ++ans; + break; + } + return ans; + } +}; + +int main() { + Solution obj; + vector<string> strs1 = {"cba", "daf", "ghi"}, strs2 = {"a", "b"}, + strs3 = {"zyx", "wvu", "tsr"}; + cout << obj.minDeletionSize(strs1) << endl; + cout << obj.minDeletionSize(strs2) << endl; + cout << obj.minDeletionSize(strs3) << endl; +} |