Skip to content

Commit d5e4666

Browse files
committed
update: 添加问题“1689.十-二进制数的最少数目”的代码和题解 (#1419)
1689 - AC.cpp+py+go+java+rust + CE.java (#1417) + (en) cpp - AC,100.00%,8.79% py - AC,38.96%,29.87% go - AC,100.00%,62.50% java - AC,5.45%,60.00% rust - AC,100.00%,63.64% rust.rust - AC,100.00%,36.36% Signed-off-by: LetMeFly666 <Tisfy@qq.com>
1 parent 624aa7b commit d5e4666

17 files changed

Lines changed: 731 additions & 4 deletions

.commitmsg

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
1689 - AC.cpp+py+go+java+rust + CE.java (#1417) + (en)
2+
3+
cpp - AC,100.00%,8.79%
4+
py - AC,38.96%,29.87%
5+
go - AC,100.00%,62.50%
6+
java - AC,5.45%,60.00%
7+
rust - AC,100.00%,63.64%
8+
rust.rust - AC,100.00%,36.36%
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2026-03-01 19:50:43
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-03-01 19:51:09
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
public:
13+
int minPartitions(string n) {
14+
char M = '0';
15+
for (char c : n) {
16+
M = max(M, c);
17+
}
18+
return M - '0';
19+
}
20+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2026-03-01 19:50:43
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-03-01 20:10:52
6+
*/
7+
package main
8+
9+
// 要的是max不是min别搞错了
10+
func max1689(a, b rune) rune {
11+
if a < b {
12+
return b
13+
}
14+
return a
15+
}
16+
17+
func minPartitions(n string) int {
18+
m := rune('0')
19+
for _, c := range n {
20+
m = max1689(m, c)
21+
}
22+
return int(byte(m) - '0')
23+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2026-03-01 19:50:43
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-03-01 20:20:09
6+
*/
7+
// THIS CANNOT BE ACCPETED
8+
class Solution {
9+
public int minPartitions(String n) {
10+
char m = '0';
11+
n.chars().forEach(c -> m = Math.max(m, (char) c));
12+
return m - '0';
13+
}
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2026-03-01 19:50:43
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2026-03-01 19:52:13
6+
'''
7+
class Solution:
8+
def minPartitions(self, n: str) -> int:
9+
return ord(max(n)) - ord('0') # 记得python str不能直接相减
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2026-03-01 19:50:43
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-03-01 20:23:19
6+
*/
7+
impl Solution {
8+
pub fn min_partitions(n: String) -> i32 {
9+
let mut m = '0';
10+
for c in n.chars() {
11+
if c > m {
12+
m = c;
13+
}
14+
}
15+
(m as i32) - ('0' as i32)
16+
}
17+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2026-03-01 19:50:43
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-03-01 20:20:21
6+
*/
7+
8+
class Solution {
9+
public int minPartitions(String n) {
10+
return n.chars().max().getAsInt() - '0';
11+
}
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2026-03-01 19:50:43
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-03-01 20:26:52
6+
*/
7+
impl Solution {
8+
pub fn min_partitions(n: String) -> i32 {
9+
(*n.as_bytes().iter().max().unwrap() - b'0') as i32
10+
}
11+
}

Codes/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
* @Author: LetMeFly
33
* @Date: 2025-08-07 14:11:36
44
* @LastEditors: LetMeFly.xyz
5-
* @LastEditTime: 2026-02-15 18:57:13
5+
* @LastEditTime: 2026-03-01 20:25:21
66
*/
77
pub struct Solution;
88

9-
include!("1523-count-odd-numbers-in-an-interval-range_20260219.rs"); // 这个fileName是会被脚本替换掉的
9+
include!("1689-partitioning-into-minimum-number-of-deci-binary-numbers_more-rust.rs"); // 这个fileName是会被脚本替换掉的
1010

1111
#[derive(Debug, PartialEq, Eq)]
1212
pub struct TreeNode {

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@
641641
|1680.连接连续二进制数字|中等|<a href="https://leetcode.cn/problems/concatenation-of-consecutive-binary-numbers/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2026/03/01/LeetCode%201680.%E8%BF%9E%E6%8E%A5%E8%BF%9E%E7%BB%AD%E4%BA%8C%E8%BF%9B%E5%88%B6%E6%95%B0%E5%AD%97/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/158535683" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/concatenation-of-consecutive-binary-numbers/solutions/3910694/letmefly-1680lian-jie-lian-xu-er-jin-zhi-54sd/" target="_blank">LeetCode题解</a>|
642642
|1684.统计一致字符串的数目|简单|<a href="https://leetcode.cn/problems/count-the-number-of-consistent-strings/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2022/11/08/LeetCode%201684.%E7%BB%9F%E8%AE%A1%E4%B8%80%E8%87%B4%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9A%84%E6%95%B0%E7%9B%AE/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/127743936" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/count-the-number-of-consistent-strings/solutions/1955993/letmefly-1684tong-ji-yi-zhi-zi-fu-chuan-d0rfp/" target="_blank">LeetCode题解</a>|
643643
|1686.石子游戏VI|中等|<a href="https://leetcode.cn/problems/stone-game-vi/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/02/02/LeetCode%201686.%E7%9F%B3%E5%AD%90%E6%B8%B8%E6%88%8FVI/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/135998504" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/stone-game-vi/solutions/2629147/letmefly-1686shi-zi-you-xi-vitan-xin-pai-8p3b/" target="_blank">LeetCode题解</a>|
644+
|1689.十-二进制数的最少数目|中等|<a href="https://leetcode.cn/problems/partitioning-into-minimum-number-of-deci-binary-numbers/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2026/03/01/LeetCode%201689.%E5%8D%81-%E4%BA%8C%E8%BF%9B%E5%88%B6%E6%95%B0%E7%9A%84%E6%9C%80%E5%B0%91%E6%95%B0%E7%9B%AE/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/158543334" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/partitioning-into-minimum-number-of-deci-binary-numbers/solutions/3911137/letmefly-1689shi-er-jin-zhi-shu-de-zui-s-5njq/" target="_blank">LeetCode题解</a>|
644645
|1694.重新格式化电话号码|简单|<a href="https://leetcode.cn/problems/reformat-phone-number/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2022/10/01/LeetCode%201694.%E9%87%8D%E6%96%B0%E6%A0%BC%E5%BC%8F%E5%8C%96%E7%94%B5%E8%AF%9D%E5%8F%B7%E7%A0%81/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/127131733" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/reformat-phone-number/solution/letmefly-1694zhong-xin-ge-shi-hua-dian-h-402n/" target="_blank">LeetCode题解</a>|
645646
|1695.删除子数组的最大得分|中等|<a href="https://leetcode.cn/problems/maximum-erasure-value/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/07/23/LeetCode%201695.%E5%88%A0%E9%99%A4%E5%AD%90%E6%95%B0%E7%BB%84%E7%9A%84%E6%9C%80%E5%A4%A7%E5%BE%97%E5%88%86/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/149602144" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/maximum-erasure-value/solutions/3732304/letmefly-1695shan-chu-zi-shu-zu-de-zui-d-sljo/" target="_blank">LeetCode题解</a>|
646647
|1700.无法吃午餐的学生数量|简单|<a href="https://leetcode.cn/problems/number-of-students-unable-to-eat-lunch/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2022/10/19/LeetCode%201700.%E6%97%A0%E6%B3%95%E5%90%83%E5%8D%88%E9%A4%90%E7%9A%84%E5%AD%A6%E7%94%9F%E6%95%B0%E9%87%8F/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/127402719" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/number-of-students-unable-to-eat-lunch/solution/letmefly-1700wu-fa-chi-wu-can-de-xue-she-o9cn/" target="_blank">LeetCode题解</a>|

0 commit comments

Comments
 (0)