代码拉取完成,页面将自动刷新
<p>You are given an array of <code>n</code> strings <code>strs</code>, all of the same length.</p>
<p>The strings can be arranged such that there is one on each line, making a grid.</p>
<ul>
<li>For example, <code>strs = ["abc", "bce", "cae"]</code> can be arranged as follows:</li>
</ul>
<pre>
abc
bce
cae
</pre>
<p>You want to <strong>delete</strong> the columns that are <strong>not sorted lexicographically</strong>. In the above example (<strong>0-indexed</strong>), columns 0 (<code>'a'</code>, <code>'b'</code>, <code>'c'</code>) and 2 (<code>'c'</code>, <code>'e'</code>, <code>'e'</code>) are sorted, while column 1 (<code>'b'</code>, <code>'c'</code>, <code>'a'</code>) is not, so you would delete column 1.</p>
<p>Return <em>the number of columns that you will delete</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["cba","daf","ghi"]
<strong>Output:</strong> 1
<strong>Explanation:</strong> The grid looks as follows:
cba
daf
ghi
Columns 0 and 2 are sorted, but column 1 is not, so you only need to delete 1 column.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> strs = ["a","b"]
<strong>Output:</strong> 0
<strong>Explanation:</strong> The grid looks as follows:
a
b
Column 0 is the only column and is sorted, so you will not delete any columns.
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> strs = ["zyx","wvu","tsr"]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The grid looks as follows:
zyx
wvu
tsr
All 3 columns are not sorted, so you will delete all 3.
</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 <= 1000</code></li>
<li><code>strs[i]</code> consists of lowercase English letters.</li>
</ul>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。