Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions solution/0700-0799/0777.Swap Adjacent in LR String/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ tags:

<!-- description:start -->

<p>In a string composed of <code>&#39;L&#39;</code>, <code>&#39;R&#39;</code>, and <code>&#39;X&#39;</code> characters, like <code>&quot;RXXLRXRXL&quot;</code>, a move consists of either replacing one occurrence of <code>&quot;XL&quot;</code> with <code>&quot;LX&quot;</code>, or replacing one occurrence of <code>&quot;RX&quot;</code> with <code>&quot;XR&quot;</code>. Given the starting string <code>start</code> and the ending string <code>end</code>, return <code>True</code> if and only if there exists a sequence of moves to transform <code>start</code> to <code>end</code>.</p>
<p>In a string composed of <code>&#39;L&#39;</code>, <code>&#39;R&#39;</code>, and <code>&#39;X&#39;</code> characters, like <code>&quot;RXXLRXRXL&quot;</code>, a move consists of either replacing one occurrence of <code>&quot;XL&quot;</code> with <code>&quot;LX&quot;</code>, or replacing one occurrence of <code>&quot;RX&quot;</code> with <code>&quot;XR&quot;</code>. Given the starting string <code>start</code> and the ending string <code>result</code>, return <code>True</code> if and only if there exists a sequence of moves to transform <code>start</code> to <code>result</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> start = &quot;RXXLRXRXL&quot;, end = &quot;XRLXXRRLX&quot;
<strong>Input:</strong> start = &quot;RXXLRXRXL&quot;, result = &quot;XRLXXRRLX&quot;
<strong>Output:</strong> true
<strong>Explanation:</strong> We can transform start to end following these steps:
<strong>Explanation:</strong> We can transform start to result following these steps:
RXXLRXRXL -&gt;
XRXLRXRXL -&gt;
XRLXRXRXL -&gt;
Expand All @@ -36,7 +36,7 @@ XRLXXRRLX
<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> start = &quot;X&quot;, end = &quot;L&quot;
<strong>Input:</strong> start = &quot;X&quot;, result = &quot;L&quot;
<strong>Output:</strong> false
</pre>

Expand All @@ -45,8 +45,8 @@ XRLXXRRLX

<ul>
<li><code>1 &lt;= start.length&nbsp;&lt;= 10<sup>4</sup></code></li>
<li><code>start.length == end.length</code></li>
<li>Both <code>start</code> and <code>end</code> will only consist of characters in <code>&#39;L&#39;</code>, <code>&#39;R&#39;</code>, and&nbsp;<code>&#39;X&#39;</code>.</li>
<li><code>start.length == result.length</code></li>
<li>Both <code>start</code> and <code>result</code> will only consist of characters in <code>&#39;L&#39;</code>, <code>&#39;R&#39;</code>, and&nbsp;<code>&#39;X&#39;</code>.</li>
</ul>

<!-- description:end -->
Expand Down
4 changes: 2 additions & 2 deletions solution/0900-0999/0909.Snakes and Ladders/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ tags:

<p>A board square on row <code>r</code> and column <code>c</code> has a snake or ladder if <code>board[r][c] != -1</code>. The destination of that snake or ladder is <code>board[r][c]</code>. Squares <code>1</code> and <code>n<sup>2</sup></code> are not the starting points of any snake or ladder.</p>

<p>Note that you only take a snake or ladder at most once per move. If the destination to a snake or ladder is the start of another snake or ladder, you do <strong>not</strong> follow the subsequent&nbsp;snake or ladder.</p>
<p>Note that you only take a snake or ladder at most once per dice roll. If the destination to a snake or ladder is the start of another snake or ladder, you do <strong>not</strong> follow the subsequent&nbsp;snake or ladder.</p>

<ul>
<li>For example, suppose the board is <code>[[-1,4],[-1,3]]</code>, and on the first move, your destination square is <code>2</code>. You follow the ladder to square <code>3</code>, but do <strong>not</strong> follow the subsequent ladder to <code>4</code>.</li>
</ul>

<p>Return <em>the least number of moves required to reach the square </em><code>n<sup>2</sup></code><em>. If it is not possible to reach the square, return </em><code>-1</code>.</p>
<p>Return <em>the least number of dice rolls required to reach the square </em><code>n<sup>2</sup></code><em>. If it is not possible to reach the square, return </em><code>-1</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ region2 = &quot;New York&quot;
<li><code>1 &lt;= regions[i][j].length, region1.length, region2.length &lt;= 20</code></li>
<li><code>region1 != region2</code></li>
<li><code>regions[i][j]</code>, <code>region1</code>, and <code>region2</code> consist of English letters.</li>
<li>The input is generated such that there exists a region which contains all the other regions, either directly or indirectly.</li>
</ul>

<!-- description:end -->
Expand Down
2 changes: 1 addition & 1 deletion solution/2600-2699/2623.Memoize/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ values = [[5],[]]
<ul>
<li><code>0 &lt;= a, b &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= n &lt;= 10</code></li>
<li><code>0 &lt;= actions.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= actions.length &lt;= 10<sup>5</sup></code></li>
<li><code>actions.length === values.length</code></li>
<li><code>actions[i]</code> is one of &quot;call&quot; and &quot;getCallCount&quot;</li>
<li><code>fnName</code> is one of &quot;sum&quot;, &quot;factorial&quot; and&nbsp;&quot;fib&quot;</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tags:

<p>In one <strong>operation</strong>, you can swap any two <strong>adjacent</strong> elements if they have the <strong>same</strong> number of <span data-keyword="set-bit">set bits</span>. You are allowed to do this operation <strong>any</strong> number of times (<strong>including zero</strong>).</p>

<p>Return <code>true</code> <em>if you can sort the array, else return </em><code>false</code>.</p>
<p>Return <code>true</code> <em>if you can sort the array in ascending order, else return </em><code>false</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tags:
<p>一个数组的 <strong>能量值</strong> 定义为:</p>

<ul>
<li>如果 <strong>所有</strong>&nbsp;元素都是依次&nbsp;<strong>连续</strong> 且 <strong>上升</strong> 的,那么能量值为 <strong>最大</strong>&nbsp;的元素。</li>
<li>如果 <strong>所有</strong>&nbsp;元素都是依次&nbsp;<strong>连续</strong>(即 <code>nums[i] + 1 = nums[i + 1]</code>,<code>i &lt; n</code>)且 <strong>上升</strong> 的,那么能量值为 <strong>最大</strong>&nbsp;的元素。</li>
<li>否则为 -1 。</li>
</ul>

Expand Down
156 changes: 156 additions & 0 deletions solution/3300-3399/3345.Smallest Divisible Digit Product I/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
---
comments: true
difficulty: 简单
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3345.Smallest%20Divisible%20Digit%20Product%20I/README.md
---

<!-- problem:start -->

# [3345. 最小可整除数位乘积 I](https://leetcode.cn/problems/smallest-divisible-digit-product-i)

[English Version](/solution/3300-3399/3345.Smallest%20Divisible%20Digit%20Product%20I/README_EN.md)

## 题目描述

<!-- description:start -->

<p>给你两个整数&nbsp;<code>n</code> 和&nbsp;<code>t</code>&nbsp;。请你返回大于等于&nbsp;<code>n</code>&nbsp;的&nbsp;<strong>最小</strong>&nbsp;整数,且该整数的&nbsp;<strong>各数位之积</strong>&nbsp;能被&nbsp;<code>t</code>&nbsp;整除。</p>

<p>&nbsp;</p>

<p><strong class="example">示例 1:</strong></p>

<div class="example-block">
<p><span class="example-io"><b>输入:</b>n = 10, t = 2</span></p>

<p><span class="example-io"><b>输出:</b>10</span></p>

<p><strong>解释:</strong></p>

<p>10 的数位乘积为 0 ,可以被 2 整除,所以它是大于等于 10 且满足题目要求的最小整数。</p>
</div>

<p><strong class="example">示例 2:</strong></p>

<div class="example-block">
<p><span class="example-io"><b>输入:</b>n = 15, t = 3</span></p>

<p><span class="example-io"><b>输出:</b>16</span></p>

<p><strong>解释:</strong></p>

<p>16 的数位乘积为 6 ,可以被 3 整除,所以它是大于等于 15 且满足题目要求的最小整数。</p>
</div>

<p>&nbsp;</p>

<p><strong>提示:</strong></p>

<ul>
<li><code>1 &lt;= n &lt;= 100</code></li>
<li><code>1 &lt;= t &lt;= 10</code></li>
</ul>

<!-- description:end -->

## 解法

<!-- solution:start -->

### 方法一:枚举

我们注意到,每 $10$ 个数里一定会出现数位乘积为 $0$ 的整数,因此我们可以直接枚举大于等于 $n$ 的整数,直到找到一个数位乘积能被 $t$ 整除的整数。

时间复杂度 $O(\log n)$,空间复杂度 $O(1)$。

<!-- tabs:start -->

#### Python3

```python
class Solution:
def smallestNumber(self, n: int, t: int) -> int:
for i in count(n):
p = 1
x = i
while x:
p *= x % 10
x //= 10
if p % t == 0:
return i
```

#### Java

```java
class Solution {
public int smallestNumber(int n, int t) {
for (int i = n;; ++i) {
int p = 1;
for (int x = i; x > 0; x /= 10) {
p *= (x % 10);
}
if (p % t == 0) {
return i;
}
}
}
}
```

#### C++

```cpp
class Solution {
public:
int smallestNumber(int n, int t) {
for (int i = n;; ++i) {
int p = 1;
for (int x = i; x > 0; x /= 10) {
p *= (x % 10);
}
if (p % t == 0) {
return i;
}
}
}
};
```

#### Go

```go
func smallestNumber(n int, t int) int {
for i := n; ; i++ {
p := 1
for x := i; x > 0; x /= 10 {
p *= x % 10
}
if p%t == 0 {
return i
}
}
}
```

#### TypeScript

```ts
function smallestNumber(n: number, t: number): number {
for (let i = n; ; ++i) {
let p = 1;
for (let x = i; x; x = Math.floor(x / 10)) {
p *= x % 10;
}
if (p % t === 0) {
return i;
}
}
}
```

<!-- tabs:end -->

<!-- solution:end -->

<!-- problem:end -->
Loading
Loading