mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
48 lines
2.1 KiB
HTML
48 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 <strong>every string (row) in lexicographic</strong> order. (i.e., <code>(strs[0][0] <= strs[0][1] <= ... <= strs[0][strs[0].length - 1])</code>, and <code>(strs[1][0] <= strs[1][1] <= ... <= strs[1][strs[1].length - 1])</code>, and so on). 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 = ["babca","bbazb"]
|
||
|
<strong>Output:</strong> 3
|
||
|
<strong>Explanation:</strong> After deleting columns 0, 1, and 4, the final array is strs = ["bc", "az"].
|
||
|
Both these rows are individually in lexicographic order (ie. strs[0][0] <= strs[0][1] and strs[1][0] <= strs[1][1]).
|
||
|
Note that strs[0] > strs[1] - the array strs is not necessarily in lexicographic order.</pre>
|
||
|
|
||
|
<p><strong>Example 2:</strong></p>
|
||
|
|
||
|
<pre>
|
||
|
<strong>Input:</strong> strs = ["edcba"]
|
||
|
<strong>Output:</strong> 4
|
||
|
<strong>Explanation:</strong> If we delete less than 4 columns, the only row will not be lexicographically sorted.
|
||
|
</pre>
|
||
|
|
||
|
<p><strong>Example 3:</strong></p>
|
||
|
|
||
|
<pre>
|
||
|
<strong>Input:</strong> strs = ["ghi","def","abc"]
|
||
|
<strong>Output:</strong> 0
|
||
|
<strong>Explanation:</strong> All rows are already lexicographically sorted.
|
||
|
</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>
|
||
|
|
||
|
<ul>
|
||
|
<li> </li>
|
||
|
</ul>
|