mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-19 12:06:48 +08:00
update
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<p>如果一个整数 <code>n</code> 在 <code>b</code> 进制下(<code>b</code> 为 <code>2</code> 到 <code>n - 2</code> 之间的所有整数)对应的字符串 <strong>全部</strong> 都是 <strong>回文的</strong> ,那么我们称这个数 <code>n</code> 是 <strong>严格回文</strong> 的。</p>
|
||||
|
||||
<p>给你一个整数 <code>n</code> ,如果 <code>n</code> 是 <strong>严格回文</strong> 的,请返回 <code>true</code> ,否则返回<em> </em><code>false</code> 。</p>
|
||||
|
||||
<p>如果一个字符串从前往后读和从后往前读完全相同,那么这个字符串是 <strong>回文的</strong> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>n = 9
|
||||
<b>输出:</b>false
|
||||
<b>解释:</b>在 2 进制下:9 = 1001 ,是回文的。
|
||||
在 3 进制下:9 = 100 ,不是回文的。
|
||||
所以,9 不是严格回文数字,我们返回 false 。
|
||||
注意在 4, 5, 6 和 7 进制下,n = 9 都不是回文的。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>n = 4
|
||||
<b>输出:</b>false
|
||||
<b>解释:</b>我们只考虑 2 进制:4 = 100 ,不是回文的。
|
||||
所以我们返回 false 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>4 <= n <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
@@ -0,0 +1,38 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始的整数数组 <code>nums</code> ,判断是否存在 <strong>两个</strong> 长度为 <code>2</code> 的子数组且它们的 <strong>和</strong> 相等。注意,这两个子数组起始位置的下标必须 <strong>不相同</strong> 。</p>
|
||||
|
||||
<p>如果这样的子数组存在,请返回 <code>true</code>,否则返回 <code>false</code><em> </em>。</p>
|
||||
|
||||
<p><strong>子数组</strong> 是一个数组中一段连续非空的元素组成的序列。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>nums = [4,2,4]
|
||||
<b>输出:</b>true
|
||||
<b>解释:</b>元素为 [4,2] 和 [2,4] 的子数组有相同的和 6 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>nums = [1,2,3,4,5]
|
||||
<b>输出:</b>false
|
||||
<b>解释:</b>没有长度为 2 的两个子数组和相等。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>nums = [0,0,0]
|
||||
<b>输出:</b>true
|
||||
<b>解释:</b>子数组 [nums[0],nums[1]] 和 [nums[1],nums[2]] 的和相等,都为 0 。
|
||||
注意即使子数组的元素相同,这两个子数组也视为不相同的子数组,因为它们在原数组中的起始位置不同。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= nums.length <= 1000</code></li>
|
||||
<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
@@ -0,0 +1,34 @@
|
||||
<p>实现 <a href="https://baike.baidu.com/item/strstr/811469" target="_blank">strStr()</a> 函数。</p>
|
||||
|
||||
<p>给你两个字符串 <code>haystack</code> 和 <code>needle</code> ,请你在 <code>haystack</code> 字符串中找出 <code>needle</code> 字符串出现的第一个位置(下标从 0 开始)。如果不存在,则返回 <code>-1</code><strong> </strong>。</p>
|
||||
|
||||
<p><strong>说明:</strong></p>
|
||||
|
||||
<p>当 <code>needle</code> 是空字符串时,我们应当返回什么值呢?这是一个在面试中很好的问题。</p>
|
||||
|
||||
<p>对于本题而言,当 <code>needle</code> 是空字符串时我们应当返回 0 。这与 C 语言的 <a href="https://baike.baidu.com/item/strstr/811469" target="_blank">strstr()</a> 以及 Java 的 <a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#indexOf(java.lang.String)" target="_blank">indexOf()</a> 定义相符。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>haystack = "hello", needle = "ll"
|
||||
<strong>输出:</strong>2
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>haystack = "aaaaa", needle = "bba"
|
||||
<strong>输出:</strong>-1
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= haystack.length, needle.length <= 10<sup>4</sup></code></li>
|
||||
<li><code>haystack</code> 和 <code>needle</code> 仅由小写英文字符组成</li>
|
||||
</ul>
|
@@ -0,0 +1,41 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始的 <code>m x n</code> 二进制矩阵 <code>mat</code> 和一个整数 <code>cols</code> ,表示你需要选出的列数。</p>
|
||||
|
||||
<p>如果一行中,所有的 <code>1</code> 都被你选中的列所覆盖,那么我们称这一行 <strong>被覆盖</strong> 了。</p>
|
||||
|
||||
<p>请你返回在选择 <code>cols</code> 列的情况下,<strong>被覆盖</strong> 的行数 <strong>最大</strong> 为多少。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2022/07/14/rowscovered.png" style="width: 250px; height: 417px;"></strong></p>
|
||||
|
||||
<pre><b>输入:</b>mat = [[0,0,0],[1,0,1],[0,1,1],[0,0,1]], cols = 2
|
||||
<b>输出:</b>3
|
||||
<strong>解释:</strong>
|
||||
如上图所示,覆盖 3 行的一种可行办法是选择第 0 和第 2 列。
|
||||
可以看出,不存在大于 3 行被覆盖的方案,所以我们返回 3 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2022/07/14/rowscovered2.png" style="width: 83px; height: 247px;"></strong></p>
|
||||
|
||||
<pre><b>输入:</b>mat = [[1],[0]], cols = 1
|
||||
<b>输出:</b>2
|
||||
<strong>解释:</strong>
|
||||
选择唯一的一列,两行都被覆盖了,原因是整个矩阵都被覆盖了。
|
||||
所以我们返回 2 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>m == mat.length</code></li>
|
||||
<li><code>n == mat[i].length</code></li>
|
||||
<li><code>1 <= m, n <= 12</code></li>
|
||||
<li><code>mat[i][j]</code> 要么是 <code>0</code> 要么是 <code>1</code> 。</li>
|
||||
<li><code>1 <= cols <= n</code></li>
|
||||
</ul>
|
@@ -0,0 +1,37 @@
|
||||
<p>你有 <code>n</code> 个机器人,给你两个下标从 <strong>0</strong> 开始的整数数组 <code>chargeTimes</code> 和 <code>runningCosts</code> ,两者长度都为 <code>n</code> 。第 <code>i</code> 个机器人充电时间为 <code>chargeTimes[i]</code> 单位时间,花费 <code>runningCosts[i]</code> 单位时间运行。再给你一个整数 <code>budget</code> 。</p>
|
||||
|
||||
<p>运行 <code>k</code> 个机器人 <strong>总开销</strong> 是 <code>max(chargeTimes) + k * sum(runningCosts)</code> ,其中 <code>max(chargeTimes)</code> 是这 <code>k</code> 个机器人中最大充电时间,<code>sum(runningCosts)</code> 是这 <code>k</code> 个机器人的运行时间之和。</p>
|
||||
|
||||
<p>请你返回在 <strong>不超过</strong> <code>budget</code> 的前提下,你 <strong>最多</strong> 可以 <strong>连续</strong> 运行的机器人数目为多少。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>chargeTimes = [3,6,1,3,4], runningCosts = [2,1,3,4,5], budget = 25
|
||||
<b>输出:</b>3
|
||||
<b>解释:</b>
|
||||
可以在 budget 以内运行所有单个机器人或者连续运行 2 个机器人。
|
||||
选择前 3 个机器人,可以得到答案最大值 3 。总开销是 max(3,6,1) + 3 * sum(2,1,3) = 6 + 3 * 6 = 24 ,小于 25 。
|
||||
可以看出无法在 budget 以内连续运行超过 3 个机器人,所以我们返回 3 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>chargeTimes = [11,12,19], runningCosts = [10,8,7], budget = 19
|
||||
<b>输出:</b>0
|
||||
<b>解释:</b>即使运行任何一个单个机器人,还是会超出 budget,所以我们返回 0 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>chargeTimes.length == runningCosts.length == n</code></li>
|
||||
<li><code>1 <= n <= 5 * 10<sup>4</sup></code></li>
|
||||
<li><code>1 <= chargeTimes[i], runningCosts[i] <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= budget <= 10<sup>15</sup></code></li>
|
||||
</ul>
|
Reference in New Issue
Block a user