mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
49 lines
2.1 KiB
HTML
49 lines
2.1 KiB
HTML
<p>You are given an array of <code>n</code> strings <code>strs</code>, all of the same length.</p>
|
|
|
|
<p>We may choose any deletion indices, and we delete all the characters in those indices for each string.</p>
|
|
|
|
<p>For example, if we have <code>strs = ["abcdef","uvwxyz"]</code> and deletion indices <code>{0, 2, 3}</code>, then the final array after deletions is <code>["bef", "vyz"]</code>.</p>
|
|
|
|
<p>Suppose we chose a set of deletion indices <code>answer</code> such that after deletions, the final array has its elements in <strong>lexicographic</strong> order (i.e., <code>strs[0] <= strs[1] <= strs[2] <= ... <= strs[n - 1]</code>). Return <em>the minimum possible value of</em> <code>answer.length</code>.</p>
|
|
|
|
<p> </p>
|
|
<p><strong>Example 1:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> strs = ["ca","bb","ac"]
|
|
<strong>Output:</strong> 1
|
|
<strong>Explanation:</strong>
|
|
After deleting the first column, strs = ["a", "b", "c"].
|
|
Now strs is in lexicographic order (ie. strs[0] <= strs[1] <= strs[2]).
|
|
We require at least 1 deletion since initially strs was not in lexicographic order, so the answer is 1.
|
|
</pre>
|
|
|
|
<p><strong>Example 2:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> strs = ["xc","yb","za"]
|
|
<strong>Output:</strong> 0
|
|
<strong>Explanation:</strong>
|
|
strs is already in lexicographic order, so we do not need to delete anything.
|
|
Note that the rows of strs are not necessarily in lexicographic order:
|
|
i.e., it is NOT necessarily true that (strs[0][0] <= strs[0][1] <= ...)
|
|
</pre>
|
|
|
|
<p><strong>Example 3:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> strs = ["zyx","wvu","tsr"]
|
|
<strong>Output:</strong> 3
|
|
<strong>Explanation:</strong> We have to delete every column.
|
|
</pre>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>n == strs.length</code></li>
|
|
<li><code>1 <= n <= 100</code></li>
|
|
<li><code>1 <= strs[i].length <= 100</code></li>
|
|
<li><code>strs[i]</code> consists of lowercase English letters.</li>
|
|
</ul>
|