Skip to content

Commit 3c204bf

Browse files
committed
update: 添加问题“1323.6和9组成的最大数字”的代码和题解 (#1085)
Signed-off-by: LetMeFly666 <[email protected]>
1 parent c2d75e2 commit 3c204bf

12 files changed

+372
-8
lines changed

.commitmsg

Lines changed: 0 additions & 7 deletions
This file was deleted.

Codes/1323-maximum-69-number.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-08-16 10:17:15
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-08-16 10:19:20
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
public:
13+
int maximum69Number (int num) {
14+
string s = to_string(num);
15+
for (char &c : s) {
16+
if (c == '6') {
17+
c = '9';
18+
break; // 记得break
19+
}
20+
}
21+
return atoi(s.c_str());
22+
}
23+
};

Codes/1323-maximum-69-number.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-08-16 10:17:15
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-08-16 10:43:00
6+
*/
7+
package main
8+
9+
import (
10+
"strconv"
11+
"strings"
12+
)
13+
14+
func maximum69Number (num int) (ans int) {
15+
s := strconv.Itoa(num)
16+
s = strings.Replace(s, "6", "9", 1)
17+
ans, _ = strconv.Atoi(s)
18+
return
19+
}

Codes/1323-maximum-69-number.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-08-16 10:17:15
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-08-16 10:46:36
6+
*/
7+
class Solution {
8+
public int maximum69Number (int num) {
9+
return Integer.parseInt(String.valueOf(num).replaceFirst("6", "9")); // java竟然一行解决了
10+
}
11+
}

Codes/1323-maximum-69-number.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2025-08-16 10:17:15
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-08-16 10:24:13
6+
'''
7+
class Solution:
8+
def maximum69Number (self, num: int) -> int:
9+
s = list(str(num))
10+
for i, c in enumerate(s):
11+
if c == '6':
12+
s[i] = '9'
13+
break
14+
return int(''.join(s)) # 记得转回int

Codes/1323-maximum-69-number.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-08-16 10:17:15
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-08-16 10:48:36
6+
*/
7+
impl Solution {
8+
pub fn maximum69_number (num: i32) -> i32 {
9+
num.to_string().replacen("6", "9", 1).parse().unwrap()
10+
}
11+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-08-16 10:17:15
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-08-16 10:34:19
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
public:
13+
int maximum69Number (int num) {
14+
int base = 0;
15+
for (int n = num, loc = 0, nowPow = 1; n; n /= 10, loc++, nowPow *= 10) {
16+
if (n % 10 == 6) {
17+
base = nowPow;
18+
}
19+
}
20+
return num + base * 3;
21+
}
22+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-08-16 10:17:15
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-08-16 10:30:45
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
public:
13+
int maximum69Number (int num) {
14+
int first6loc = -1;
15+
for (int n = num, loc = 0; n; n /= 10, loc++) {
16+
if (n % 10 == 6) {
17+
first6loc = loc;
18+
}
19+
}
20+
if (first6loc == -1) {
21+
return num;
22+
}
23+
return num + 3 * pow(10, first6loc);
24+
}
25+
};

Codes/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
* @LastEditTime: 2025-08-11 22:07:08
66
*/
77
pub struct Solution;
8-
include!("0342-power-of-four_20250815.rs"); // 这个fileName是会被脚本替换掉的
8+
include!("1323-maximum-69-number.rs"); // 这个fileName是会被脚本替换掉的

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@
514514
|1295.统计位数为偶数的数字|简单|<a href="https://leetcode.cn/problems/find-numbers-with-even-number-of-digits/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/04/30/LeetCode%201295.%E7%BB%9F%E8%AE%A1%E4%BD%8D%E6%95%B0%E4%B8%BA%E5%81%B6%E6%95%B0%E7%9A%84%E6%95%B0%E5%AD%97/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/147637587" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-numbers-with-even-number-of-digits/solutions/3666390/letmefly-1295tong-ji-wei-shu-wei-ou-shu-bwhfr/" target="_blank">LeetCode题解</a>|
515515
|1299.将每个元素替换为右侧最大元素|简单|<a href="https://leetcode.cn/problems/replace-elements-with-greatest-element-on-right-side/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/02/16/LeetCode%201299.%E5%B0%86%E6%AF%8F%E4%B8%AA%E5%85%83%E7%B4%A0%E6%9B%BF%E6%8D%A2%E4%B8%BA%E5%8F%B3%E4%BE%A7%E6%9C%80%E5%A4%A7%E5%85%83%E7%B4%A0/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/145661909" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/replace-elements-with-greatest-element-on-right-side/solutions/3076497/letmefly-1299jiang-mei-ge-yuan-su-ti-hua-4y58/" target="_blank">LeetCode题解</a>|
516516
|1302.层数最深叶子节点的和|中等|<a href="https://leetcode.cn/problems/deepest-leaves-sum/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2022/08/17/LeetCode%201302.%E5%B1%82%E6%95%B0%E6%9C%80%E6%B7%B1%E5%8F%B6%E5%AD%90%E8%8A%82%E7%82%B9%E7%9A%84%E5%92%8C/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/126377912" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/deepest-leaves-sum/solution/letmefly-1302ceng-shu-zui-shen-xie-zi-ji-eyu0/" target="_blank">LeetCode题解</a>|
517+
|1323.6和9组成的最大数字|简单|<a href="https://leetcode.cn/problems/maximum-69-number/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/08/16/LeetCode%201323.6%E5%92%8C9%E7%BB%84%E6%88%90%E7%9A%84%E6%9C%80%E5%A4%A7%E6%95%B0%E5%AD%97/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/150443019" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/maximum-69-number/solutions/3754470/letmefly-13236-he-9-zu-cheng-de-zui-da-s-hqw5/" target="_blank">LeetCode题解</a>|
517518
|1328.破坏回文串|中等|<a href="https://leetcode.cn/problems/break-a-palindrome/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/03/05/LeetCode%201328.%E7%A0%B4%E5%9D%8F%E5%9B%9E%E6%96%87%E4%B8%B2/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/146046025" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/break-a-palindrome/solutions/3597648/letmefly-1328po-pi-hui-wen-chuan-tan-xin-ktbc/" target="_blank">LeetCode题解</a>|
518519
|1329.将矩阵按对角线排序|中等|<a href="https://leetcode.cn/problems/sort-the-matrix-diagonally/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/04/29/LeetCode%201329.%E5%B0%86%E7%9F%A9%E9%98%B5%E6%8C%89%E5%AF%B9%E8%A7%92%E7%BA%BF%E6%8E%92%E5%BA%8F/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/138329644" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/sort-the-matrix-diagonally/solutions/2761288/letmefly-1329jiang-ju-zhen-an-dui-jiao-x-nu18/" target="_blank">LeetCode题解</a>|
519520
|1331.数组序号转换|简单|<a href="https://leetcode.cn/problems/rank-transform-of-an-array/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2022/07/28/LeetCode%201331.%E6%95%B0%E7%BB%84%E5%BA%8F%E5%8F%B7%E8%BD%AC%E6%8D%A2/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/126030218" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/rank-transform-of-an-array/solution/letmefly-1331shu-zu-xu-hao-zhuan-huan-by-p3j3/" target="_blank">LeetCode题解</a>|

0 commit comments

Comments
 (0)