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
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ tags:
<strong>输出:</strong>22
<strong>解释:</strong>
22 是一个数值平衡数,因为:
- 数字 2 出现 2 次
- 数字 2 出现 2 次
这也是严格大于 1 的最小数值平衡数。
</pre>

Expand All @@ -47,7 +47,7 @@ tags:
<strong>解释:</strong>
1333 是一个数值平衡数,因为:
- 数字 1 出现 1 次。
- 数字 3 出现 3 次。
- 数字 3 出现 3 次。
这也是严格大于 1000 的最小数值平衡数。
注意,1022 不能作为本输入的答案,因为数字 0 的出现次数超过了 0 。</pre>

Expand All @@ -59,7 +59,7 @@ tags:
<strong>解释:</strong>
3133 是一个数值平衡数,因为:
- 数字 1 出现 1 次。
- 数字 3 出现 3 次。
- 数字 3 出现 3 次。
这也是严格大于 3000 的最小数值平衡数。
</pre>

Expand Down Expand Up @@ -197,6 +197,38 @@ function nextBeautifulNumber(n: number): number {
}
```

#### Rust

```rust
impl Solution {
pub fn next_beautiful_number(n: i32) -> i32 {
let mut x = n + 1;
loop {
let mut cnt = [0; 10];
let mut y = x;
while y > 0 {
cnt[(y % 10) as usize] += 1;
y /= 10;
}
let mut ok = true;
let mut y2 = x;
while y2 > 0 {
let d = (y2 % 10) as usize;
if d != cnt[d] {
ok = false;
break;
}
y2 /= 10;
}
if ok {
return x;
}
x += 1;
}
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ tags:
<pre>
<strong>Input:</strong> n = 1
<strong>Output:</strong> 22
<strong>Explanation:</strong>
<strong>Explanation:</strong>
22 is numerically balanced since:
- The digit 2 occurs 2 times.
- The digit 2 occurs 2 times.
It is also the smallest numerically balanced number strictly greater than 1.
</pre>

Expand All @@ -43,10 +43,10 @@ It is also the smallest numerically balanced number strictly greater than 1.
<pre>
<strong>Input:</strong> n = 1000
<strong>Output:</strong> 1333
<strong>Explanation:</strong>
<strong>Explanation:</strong>
1333 is numerically balanced since:
- The digit 1 occurs 1 time.
- The digit 3 occurs 3 times.
- The digit 3 occurs 3 times.
It is also the smallest numerically balanced number strictly greater than 1000.
Note that 1022 cannot be the answer because 0 appeared more than 0 times.
</pre>
Expand All @@ -56,7 +56,7 @@ Note that 1022 cannot be the answer because 0 appeared more than 0 times.
<pre>
<strong>Input:</strong> n = 3000
<strong>Output:</strong> 3133
<strong>Explanation:</strong>
<strong>Explanation:</strong>
3133 is numerically balanced since:
- The digit 1 occurs 1 time.
- The digit 3 occurs 3 times.
Expand Down Expand Up @@ -196,6 +196,38 @@ function nextBeautifulNumber(n: number): number {
}
```

#### Rust

```rust
impl Solution {
pub fn next_beautiful_number(n: i32) -> i32 {
let mut x = n + 1;
loop {
let mut cnt = [0; 10];
let mut y = x;
while y > 0 {
cnt[(y % 10) as usize] += 1;
y /= 10;
}
let mut ok = true;
let mut y2 = x;
while y2 > 0 {
let d = (y2 % 10) as usize;
if d != cnt[d] {
ok = false;
break;
}
y2 /= 10;
}
if ok {
return x;
}
x += 1;
}
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
impl Solution {
pub fn next_beautiful_number(n: i32) -> i32 {
let mut x = n + 1;
loop {
let mut cnt = [0; 10];
let mut y = x;
while y > 0 {
cnt[(y % 10) as usize] += 1;
y /= 10;
}
let mut ok = true;
let mut y2 = x;
while y2 > 0 {
let d = (y2 % 10) as usize;
if d != cnt[d] {
ok = false;
break;
}
y2 /= 10;
}
if ok {
return x;
}
x += 1;
}
}
}