Skip to content

Commit f119648

Browse files
authored
update: 添加问题“3461.判断操作后字符串中的数字是否相等I”的代码和题解 (#1185)
* docs: 毕设月报 - 2025.08 Signed-off-by: LetMeFly666 <[email protected]> * docs Signed-off-by: LetMeFly666 <[email protected]> * docs: 毕设月报2025.9 * docs: word(yesterday) + 毕设月报2025.9+2025.10.half + 小红书笔试前两题 * word: en today + 毕设部分内容 (#1184) * 3461: init (#1184) * 3461: TLE.cpp (#1184) * 3461: WA.cpp (#1184) * 3461: AC.cpp+py + CE.go (#1184) cpp - AC,43.56%,21.78% py - AC,84.04%,89.36% * 3461: AC.go + CE.java (#1184) go - AC,100.00%,41.67% java果然CE了 * 3461: CE.java (#1184) java byte+byte=int * update: 添加问题“3461.判断操作后字符串中的数字是否相等I”的代码和题解 (#1185) Signed-off-by: LetMeFly666 <[email protected]> * docs: 润色语言 3461: AC.java+rust (#1184) java - AC,87.36%,52.87% rust - AC,100.00%,80.00% --------- Signed-off-by: LetMeFly666 <[email protected]>
1 parent b2aacf4 commit f119648

16 files changed

+491
-1
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-10-23 23:05:13
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-10-23 23:24:34
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
/*
12+
>>> ord('0')
13+
48
14+
>>> ord('0') * 2
15+
96
16+
>>> chr(96)
17+
'`'
18+
>>> ord('`')
19+
96
20+
*/
21+
class Solution {
22+
public:
23+
bool hasSameDigits(string s) {
24+
while (s.size() > 2) {
25+
string newS;
26+
for (int i = 1; i < s.size(); i++) {
27+
// cout << '(' << s[i - 1] << '+' << s[i] << " - '`') % 10 + '0' = " << char((s[i - 1] + s[i] - '`') % 10 + '0') << endl;
28+
newS.push_back((s[i - 1] + s[i] - '`') % 10 + '0');
29+
}
30+
s = move(newS);
31+
// cout << s << endl;
32+
}
33+
return s[0] == s[1];
34+
}
35+
};
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-10-23 23:05:13
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-10-23 23:32:07
6+
*/
7+
package main
8+
9+
func hasSameDigits(s string) bool {
10+
a := make([]byte, len(s))
11+
for i := range s {
12+
a[i] = s[i] - '0'
13+
}
14+
for len(a) > 2 {
15+
b := make([]byte,len(a) - 1)
16+
for i := range b {
17+
b[i] = (a[i] + a[i + 1]) % 10
18+
}
19+
a = b
20+
}
21+
return a[0] == a[1]
22+
}
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-10-23 23:05:13
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-10-23 23:42:40
6+
*/
7+
class Solution {
8+
public boolean hasSameDigits(String s) {
9+
int[] a = new int[s.length()];
10+
for (int i = 0; i < s.length(); i++) {
11+
a[i] = (s.charAt(i) - '0');
12+
}
13+
while (a.length > 2) {
14+
int[] b = new int[a.length - 1];
15+
for (int i = 0; i < b.length; i++) {
16+
b[i] = (a[i] + a[i + 1]) % 10;
17+
}
18+
a = b;
19+
}
20+
return a[0] == a[1];
21+
}
22+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2025-10-23 23:05:13
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-10-23 23:28:23
6+
'''
7+
class Solution:
8+
def hasSameDigits(self, s: str) -> bool:
9+
a = list(map(lambda c: ord(c) - ord('0'), s))
10+
while len(a) > 2:
11+
b = [0] * (len(a) - 1)
12+
for i in range(len(a) - 1):
13+
b[i] = (a[i] + a[i + 1]) % 10
14+
a = b
15+
return a[0] == a[1]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-10-23 23:05:13
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-10-23 23:46:40
6+
*/
7+
impl Solution {
8+
pub fn has_same_digits(s: String) -> bool {
9+
let mut a: Vec<u8> = s.chars()
10+
.map(|c| c.to_digit(10).unwrap() as u8)
11+
.collect();
12+
while a.len() > 2 {
13+
let mut b = Vec::with_capacity(a.len() - 1);
14+
for i in 0..a.len() - 1 {
15+
b.push((a[i] + a[i + 1]) % 10);
16+
}
17+
a = b;
18+
}
19+
a[0] == a[1]
20+
}
21+
}

Codes/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
* @LastEditTime: 2025-10-11 18:47:55
66
*/
77
pub struct Solution;
8-
include!("2011-final-value-of-variable-after-performing-operations_20251020.rs"); // 这个fileName是会被脚本替换掉的
8+
include!("3461-check-if-digits-are-equal-in-string-after-operations-i.rs"); // 这个fileName是会被脚本替换掉的

Codes/xiaohongshu2025-01.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-10-22 18:56:56
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-10-22 19:27:43
6+
*/
7+
// 发卷发了1min多
8+
#include <bits/stdc++.h>
9+
using namespace std;
10+
typedef long long ll;
11+
12+
/*
13+
2
14+
36 15
15+
16+
114
17+
*/
18+
int main() {
19+
int N;
20+
cin >> N;
21+
int bit[11] = {0};
22+
int num[10] = {0};
23+
int cnt = 0;
24+
while (N--) {
25+
int t;
26+
cin >> t;
27+
string s = to_string(t);
28+
for (int i = 0; i < s.size(); i++) {
29+
bit[i]++;
30+
num[s[i] - '0']++;
31+
cnt++;
32+
}
33+
}
34+
ll ans = 0;
35+
ll locBit = 0, k = 1, locNum = 0;
36+
while (cnt--) {
37+
while (num[locNum] == 0) {
38+
locNum++;
39+
}
40+
while (bit[locBit] == 0) {
41+
locBit++;
42+
k *= 10;
43+
}
44+
num[locNum]--;
45+
bit[locBit]--;
46+
ans += k * locNum;
47+
}
48+
cout << ans << endl;
49+
return 0;
50+
}

Codes/xiaohongshu2025-02.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-10-22 19:37:35
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-10-22 19:42:07
6+
*/
7+
#include <bits/stdc++.h>
8+
using namespace std;
9+
typedef long long ll;
10+
11+
/*
12+
5
13+
11101
14+
15+
2
16+
*/
17+
/*
18+
10
19+
1100010101
20+
21+
8
22+
*/
23+
int main() {
24+
int n;
25+
cin >> n;
26+
string s;
27+
cin >> s;
28+
char first = s[0];
29+
int canDestroy = 0;
30+
int destroyed = 0;
31+
int cntFirst = 0;
32+
for (char c : s) {
33+
if (c == first) {
34+
cntFirst++;
35+
if (canDestroy) {
36+
canDestroy--;
37+
destroyed++;
38+
}
39+
} else {
40+
canDestroy++;
41+
}
42+
}
43+
cout << n - (cntFirst - destroyed) << endl;
44+
return 0;
45+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,7 @@
10371037
|3439.重新安排会议得到最多空余时间I|中等|<a href="https://leetcode.cn/problems/reschedule-meetings-for-maximum-free-time-i/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/07/13/LeetCode%203439.%E9%87%8D%E6%96%B0%E5%AE%89%E6%8E%92%E4%BC%9A%E8%AE%AE%E5%BE%97%E5%88%B0%E6%9C%80%E5%A4%9A%E7%A9%BA%E4%BD%99%E6%97%B6%E9%97%B4I/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/149317430" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/reschedule-meetings-for-maximum-free-time-i/solutions/3722937/letmefly-3439zhong-xin-an-pai-hui-yi-de-r3t9e/" target="_blank">LeetCode题解</a>|
10381038
|3442.奇偶频次间的最大差值I|简单|<a href="https://leetcode.cn/problems/maximum-difference-between-even-and-odd-frequency-i/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/06/10/LeetCode%203442.%E5%A5%87%E5%81%B6%E9%A2%91%E6%AC%A1%E9%97%B4%E7%9A%84%E6%9C%80%E5%A4%A7%E5%B7%AE%E5%80%BCI/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/148570777" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/maximum-difference-between-even-and-odd-frequency-i/solutions/3697605/letmefly-3442qi-ou-pin-ci-jian-de-zui-da-nwwx/" target="_blank">LeetCode题解</a>|
10391039
|3459.最长V形对角线段的长度|困难|<a href="https://leetcode.cn/problems/length-of-longest-v-shaped-diagonal-segment/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/08/31/LeetCode%203459.%E6%9C%80%E9%95%BFV%E5%BD%A2%E5%AF%B9%E8%A7%92%E7%BA%BF%E6%AE%B5%E7%9A%84%E9%95%BF%E5%BA%A6/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/151050078" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/length-of-longest-v-shaped-diagonal-segment/solutions/3768545/letmefly-3459zui-chang-v-xing-dui-jiao-x-gu8q/" target="_blank">LeetCode题解</a>|
1040+
|3461.判断操作后字符串中的数字是否相等I|简单|<a href="https://leetcode.cn/problems/check-if-digits-are-equal-in-string-after-operations-i/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/10/23/LeetCode%203461.%E5%88%A4%E6%96%AD%E6%93%8D%E4%BD%9C%E5%90%8E%E5%AD%97%E7%AC%A6%E4%B8%B2%E4%B8%AD%E7%9A%84%E6%95%B0%E5%AD%97%E6%98%AF%E5%90%A6%E7%9B%B8%E7%AD%89I/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/153800840" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/check-if-digits-are-equal-in-string-after-operations-i/solutions/3814120/letmefly-3461pan-duan-cao-zuo-hou-zi-fu-8nd1t/" target="_blank">LeetCode题解</a>|
10401041
|3494.酿造药水需要的最少总时间|中等|<a href="https://leetcode.cn/problems/find-the-minimum-amount-of-time-to-brew-potions/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/10/09/LeetCode%203494.%E9%85%BF%E9%80%A0%E8%8D%AF%E6%B0%B4%E9%9C%80%E8%A6%81%E7%9A%84%E6%9C%80%E5%B0%91%E6%80%BB%E6%97%B6%E9%97%B4/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/152847907" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-the-minimum-amount-of-time-to-brew-potions/solutions/3801656/letmefly-3494niang-zao-yao-shui-xu-yao-d-bjxv/" target="_blank">LeetCode题解</a>|
10411042
|3508.设计路由器|中等|<a href="https://leetcode.cn/problems/implement-router/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/09/20/LeetCode%203508.%E8%AE%BE%E8%AE%A1%E8%B7%AF%E7%94%B1%E5%99%A8/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/151901838" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/implement-router/solutions/3787451/letmefly-3508she-ji-lu-you-qi-stltao-stl-ehkf/" target="_blank">LeetCode题解</a>|
10421043
|3516.找到最近的人|简单|<a href="https://leetcode.cn/problems/find-closest-person/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/09/04/LeetCode%203516.%E6%89%BE%E5%88%B0%E6%9C%80%E8%BF%91%E7%9A%84%E4%BA%BA/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/151184074" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-closest-person/solutions/3772009/letmefly-3516zhao-dao-zui-jin-de-ren-ji-8rlbz/" target="_blank">LeetCode题解</a>|

0 commit comments

Comments
 (0)