Skip to content

Commit 8bcc85f

Browse files
authored
update: 添加问题“3335.字符串转换后的长度I”的代码和题解(#934)
* 3335: WA.Cpp (#931) Signed-off-by: LetMeFly666 <[email protected]> * 3335: RE.Cpp (#931) Signed-off-by: LetMeFly666 <[email protected]> * 3335: AC.Cpp - AC,92.65%,98.53% (#931) Signed-off-by: LetMeFly666 <[email protected]> * 3335: Init.Py (#931) Signed-off-by: LetMeFly666 <[email protected]> * 3335: Ac.Py - AC,64.71%,94.12% (#931) Signed-off-by: LetMeFly666 <[email protected]> * 3335: Ac.Java - AC,61.29%,67.74% (#931) Signed-off-by: LetMeFly666 <[email protected]> * 3335: WA.go (#931) Signed-off-by: LetMeFly666 <[email protected]> * 3335: AC.go - AC,66.67%,66.67% (#931) Signed-off-by: LetMeFly666 <[email protected]> * update: 添加问题“3335.字符串转换后的长度I”的代码和题解(#934) Signed-off-by: LetMeFly666 <[email protected]> --------- Signed-off-by: LetMeFly666 <[email protected]>
1 parent bffbeb1 commit 8bcc85f

8 files changed

+406
-57
lines changed

.gitlog

Lines changed: 51 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,51 @@
1-
PS F:\OtherApps\Program\Git\Store\Store20_LeetCode> git pull origin master
2-
remote: Enumerating objects: 67621, done.
3-
remote: Counting objects: 100% (67607/67607), done.
4-
remote: Compressing objects: 100% (56572/56572), done.
5-
Receiving objects: 96% (64917/67621), 6.93 MiB | 1.34 MiB/sremote: Total 67621 (delta 8391), reused 65021 (delta 5814), pack-reused 14 (from 1)
6-
Receiving objects: 100% (67621/67621), 7.61 MiB | 941.00 KiB/s, done.
7-
Resolving deltas: 100% (8391/8391), completed with 21 local objects.
8-
From github.com:LetMeFly666/LeetCode
9-
* branch master -> FETCH_HEAD
10-
0b5a1edae4c..9ff5f88f71e master -> origin/master
11-
error: invalid path 'AllProblems/1082.销售分析 I /1082.销售分析 I .md'
12-
error: invalid path 'AllProblems/69.x 的平方根 /69.x 的平方根 .md'
13-
error: invalid path 'AllProblems/69.x 的平方根 /code.2.py'
14-
error: invalid path 'AllProblems/69.x 的平方根 /code.c'
15-
error: invalid path 'AllProblems/69.x 的平方根 /code.cj'
16-
error: invalid path 'AllProblems/69.x 的平方根 /code.cpp'
17-
error: invalid path 'AllProblems/69.x 的平方根 /code.cs'
18-
error: invalid path 'AllProblems/69.x 的平方根 /code.dart'
19-
error: invalid path 'AllProblems/69.x 的平方根 /code.erl'
20-
error: invalid path 'AllProblems/69.x 的平方根 /code.ex'
21-
error: invalid path 'AllProblems/69.x 的平方根 /code.go'
22-
error: invalid path 'AllProblems/69.x 的平方根 /code.java'
23-
error: invalid path 'AllProblems/69.x 的平方根 /code.js'
24-
error: invalid path 'AllProblems/69.x 的平方根 /code.kt'
25-
error: invalid path 'AllProblems/69.x 的平方根 /code.php'
26-
error: invalid path 'AllProblems/69.x 的平方根 /code.py'
27-
error: invalid path 'AllProblems/69.x 的平方根 /code.racket'
28-
error: invalid path 'AllProblems/69.x 的平方根 /code.rb'
29-
error: invalid path 'AllProblems/69.x 的平方根 /code.rs'
30-
error: invalid path 'AllProblems/69.x 的平方根 /code.sc'
31-
error: invalid path 'AllProblems/69.x 的平方根 /code.swift'
32-
error: invalid path 'AllProblems/69.x 的平方根 /code.ts'
33-
error: invalid path 'AllProblems/69.x 的平方根 /titleSlug.txt'
34-
error: invalid path 'AllProblems/LCR 084.全排列 II /LCR 084.全排列 II .md'
35-
error: invalid path 'AllProblems/LCR 084.全排列 II /code.2.py'
36-
error: invalid path 'AllProblems/LCR 084.全排列 II /code.c'
37-
error: invalid path 'AllProblems/LCR 084.全排列 II /code.cpp'
38-
error: invalid path 'AllProblems/LCR 084.全排列 II /code.cs'
39-
error: invalid path 'AllProblems/LCR 084.全排列 II /code.erl'
40-
error: invalid path 'AllProblems/LCR 084.全排列 II /code.ex'
41-
error: invalid path 'AllProblems/LCR 084.全排列 II /code.go'
42-
error: invalid path 'AllProblems/LCR 084.全排列 II /code.java'
43-
error: invalid path 'AllProblems/LCR 084.全排列 II /code.js'
44-
error: invalid path 'AllProblems/LCR 084.全排列 II /code.kt'
45-
error: invalid path 'AllProblems/LCR 084.全排列 II /code.php'
46-
error: invalid path 'AllProblems/LCR 084.全排列 II /code.py'
47-
error: invalid path 'AllProblems/LCR 084.全排列 II /code.racket'
48-
error: invalid path 'AllProblems/LCR 084.全排列 II /code.rb'
49-
error: invalid path 'AllProblems/LCR 084.全排列 II /code.rs'
50-
error: invalid path 'AllProblems/LCR 084.全排列 II /code.sc'
51-
error: invalid path 'AllProblems/LCR 084.全排列 II /code.swift'
52-
error: invalid path 'AllProblems/LCR 084.全排列 II /code.ts'
53-
error: invalid path 'AllProblems/LCR 084.全排列 II /titleSlug.txt'
54-
error: invalid path 'AllProblems/剑指 Offer II 004.只出现一次的数字 /剑指 Offer II 004.只出现一次的数字 .md'
55-
error: invalid path 'AllProblems/剑指 Offer II 084.含有重复元素集合的全排列 /剑指 Offer II 084.含有重复元素集合的全排列 .md'
56-
error: invalid path 'AllProblems/剑指 Offer II 087.复原 IP /剑指 Offer II 087.复原 IP .md'
57-
Updating 0b5a1edae4c..9ff5f88f71e
1+
C:\Users\LetMeFly>F:\LetMeFly\TFpath\打卡.py
2+
[https://leetcode-cn.com/share/daily-question/letmefly-2/197865017/]输入题目链接:https://leetcode.cn/share/daily-question/Tisfy/629375877/
3+
https://leetcode-cn.com/problems/minimize-maximum-pair-sum-in-array/]输入打卡链接:https://leetcode.cn/problems/finding-3-digit-even-numbers/submissions/
4+
[1877. 数组中最大数对和的最小值]输入题目名称:2094. 找出 3 位偶数
5+
remote: Enumerating objects: 150, done.
6+
remote: Counting objects: 100% (56/56), done.
7+
remote: Compressing objects: 100% (32/32), done.
8+
remote: Total 150 (delta 40), reused 28 (delta 13), pack-reused 94 (from 1)
9+
Receiving objects: 100% (150/150), 106.18 KiB | 364.00 KiB/s, done.
10+
Resolving deltas: 100% (108/108), completed with 1 local object.
11+
From github.com:LetMeFly666/various
12+
bff8d38..1d75d6a dev -> original/dev
13+
bff8d38..1d75d6a master -> original/master
14+
Updating bff8d38..1d75d6a
15+
Fast-forward
16+
ACM/LeetCode/index.html | 60 ++++++++++++++++++++++++++++++++++++++++++++++++-
17+
1 file changed, 59 insertions(+), 1 deletion(-)
18+
Switched to branch 'master'
19+
Your branch is behind 'original/master' by 30 commits, and can be fast-forwarded.
20+
(use "git pull" to update your local branch)
21+
Updating bff8d38..1d75d6a
22+
Fast-forward
23+
ACM/LeetCode/index.html | 60 ++++++++++++++++++++++++++++++++++++++++++++++++-
24+
1 file changed, 59 insertions(+), 1 deletion(-)
25+
Switched to branch 'dev'
26+
Your branch is up to date with 'original/dev'.
27+
28+
F:\OtherApps\Program\Git\Store\Store2_Web_Various\various\ACM\LeetCode>git add . & git commit -m "LeetCode又打卡了,题目2094. 找出 3 位偶数[https://leetcode.cn/share/daily-question/Tisfy/629375877/],打卡链接:https://leetcode.cn/problems/finding-3-digit-even-numbers/submissions/" & git checkout master & git merge dev & git push & git checkout dev & git push
29+
[dev 3449870] LeetCode又打卡了,题目2094. 找出 3 位偶数[https://leetcode.cn/share/daily-question/Tisfy/629375877/],打卡链接:https://leetcode.cn/problems/finding-3-digit-even-numbers/submissions/
30+
1 file changed, 2 insertions(+)
31+
Switched to branch 'master'
32+
Your branch is up to date with 'original/master'.
33+
Updating 1d75d6a..3449870
34+
Fast-forward
35+
ACM/LeetCode/index.html | 2 ++
36+
1 file changed, 2 insertions(+)
37+
Enumerating objects: 9, done.
38+
Counting objects: 100% (9/9), done.
39+
Delta compression using up to 12 threads
40+
Compressing objects: 100% (4/4), done.
41+
Writing objects: 100% (5/5), 4.96 KiB | 4.96 MiB/s, done.
42+
Total 5 (delta 3), reused 0 (delta 0), pack-reused 0
43+
remote: Resolving deltas: 100% (3/3), completed with 3 local objects.
44+
To github.com:LetMeFly666/various.git
45+
1d75d6a..3449870 master -> master
46+
Switched to branch 'dev'
47+
Your branch is ahead of 'original/dev' by 1 commit.
48+
(use "git push" to publish your local commits)
49+
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
50+
To github.com:LetMeFly666/various.git
51+
1d75d6a..3449870 dev -> dev
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-05-13 09:02:15
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-05-13 09:15:09
6+
* @Description: 3335: AC,92.65%,98.53%
7+
*/
8+
#if defined(_WIN32) || defined(__APPLE__)
9+
#include "_[1,2]toVector.h"
10+
#endif
11+
12+
const int MOD = 1e9 + 7;
13+
14+
class Solution {
15+
public:
16+
int lengthAfterTransformations(string s, int t) {
17+
int cnt[26] = {0};
18+
for (char c : s) {
19+
cnt[c - 'a']++;
20+
}
21+
int ans = s.size();
22+
while (t--) {
23+
int z = cnt[25];
24+
for (int i = 24; i >= 0; i--) { // 这里必须从后往前
25+
cnt[i + 1] = cnt[i];
26+
}
27+
cnt[0] = z;
28+
cnt[1] = (cnt[1] + z) % MOD;
29+
ans = (ans + z) % MOD;
30+
// debug(cnt);
31+
}
32+
return ans;
33+
}
34+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-05-13 09:02:15
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-05-13 09:28:34
6+
*/
7+
package main
8+
9+
var MOD3351 = 1000000007
10+
11+
func lengthAfterTransformations(s string, t int) int {
12+
cnt := make([]int, 26)
13+
for i := 0; i < len(s); i++ {
14+
cnt[s[i] - 'a']++
15+
}
16+
ans := len(s)
17+
for i := 0; i < t; i++ {
18+
z := cnt[25]
19+
for j := 24; j >= 0; j-- {
20+
cnt[j + 1] = cnt[j]
21+
}
22+
cnt[0] = z
23+
cnt[1] = (cnt[1] + z) % MOD3351
24+
ans = (ans + z) % MOD3351
25+
}
26+
return ans
27+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-05-13 09:02:15
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-05-13 09:19:43
6+
*/
7+
8+
class Solution {
9+
private final int MOD = 1000000007;
10+
11+
public int lengthAfterTransformations(String s, int t) {
12+
int[] cnt = new int[26];
13+
for (int i = 0; i < s.length(); i++) {
14+
cnt[s.charAt(i) - 'a']++;
15+
}
16+
int ans = s.length();
17+
while (t-- > 0) {
18+
int z = cnt[25];
19+
for (int i = 24; i >= 0; i--) {
20+
cnt[i + 1] = cnt[i];
21+
}
22+
cnt[0] = z;
23+
cnt[1] = (cnt[1] + z) % MOD;
24+
ans = (ans + z) % MOD;
25+
}
26+
return ans;
27+
}
28+
}
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-05-13 09:02:15
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-05-13 09:18:14
6+
'''
7+
MOD = 1000000007
8+
9+
class Solution:
10+
def lengthAfterTransformations(self, s: str, t: int) -> int:
11+
cnt = [0] * 26
12+
for c in s:
13+
cnt[ord(c) - 97] += 1
14+
ans = len(s)
15+
for _ in range(t):
16+
z = cnt[-1]
17+
for i in range(24, -1, -1):
18+
cnt[i + 1] = cnt[i]
19+
cnt[0] = z
20+
cnt[1] = (cnt[1] + z) % MOD
21+
ans = (ans + z) % MOD
22+
return ans

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,7 @@
963963
|3297.统计重新排列后包含另一个字符串的子字符串数目I|中等|<a href="https://leetcode.cn/problems/count-substrings-that-can-be-rearranged-to-contain-a-string-i/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/01/09/LeetCode%203297.%E7%BB%9F%E8%AE%A1%E9%87%8D%E6%96%B0%E6%8E%92%E5%88%97%E5%90%8E%E5%8C%85%E5%90%AB%E5%8F%A6%E4%B8%80%E4%B8%AA%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9A%84%E5%AD%90%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%95%B0%E7%9B%AEI/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/145031494" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/count-substrings-that-can-be-rearranged-to-contain-a-string-i/solutions/3042787/letmefly-3297tong-ji-zhong-xin-pai-lie-h-8ele/" target="_blank">LeetCode题解</a>|
964964
|3305.元音辅音字符串计数I|中等|<a href="https://leetcode.cn/problems/count-of-substrings-containing-every-vowel-and-k-consonants-i/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/03/12/LeetCode%203305.%E5%85%83%E9%9F%B3%E8%BE%85%E9%9F%B3%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%AE%A1%E6%95%B0I/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/146197747" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/count-of-substrings-containing-every-vowel-and-k-consonants-i/solutions/3607571/letmefly-3305yuan-yin-fu-yin-zi-fu-chuan-ptkg/" target="_blank">LeetCode题解</a>|
965965
|3306.元音辅音字符串计数II|中等|<a href="https://leetcode.cn/problems/count-of-substrings-containing-every-vowel-and-k-consonants-ii/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/03/13/LeetCode%203306.%E5%85%83%E9%9F%B3%E8%BE%85%E9%9F%B3%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%AE%A1%E6%95%B0II/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/146228751" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/count-of-substrings-containing-every-vowel-and-k-consonants-ii/solutions/3609545/letmefly-3306yuan-yin-fu-yin-zi-fu-chuan-7y2q/" target="_blank">LeetCode题解</a>|
966+
|3335.字符串转换后的长度I|中等|<a href="https://leetcode.cn/problems/total-characters-in-string-after-transformations-i/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/05/13/LeetCode%203335.%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%BD%AC%E6%8D%A2%E5%90%8E%E7%9A%84%E9%95%BF%E5%BA%A6I/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/147916305" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/total-characters-in-string-after-transformations-i/solutions/3675555/letmefly-3335zi-fu-chuan-zhuan-huan-hou-9ck9y/" target="_blank">LeetCode题解</a>|
966967
|3340.检查平衡字符串|简单|<a href="https://leetcode.cn/problems/check-balanced-string/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/03/14/LeetCode%203340.%E6%A3%80%E6%9F%A5%E5%B9%B3%E8%A1%A1%E5%AD%97%E7%AC%A6%E4%B8%B2/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/146249653" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/check-balanced-string/solutions/3610899/letmefly-3340jian-cha-ping-heng-zi-fu-ch-p8eo/" target="_blank">LeetCode题解</a>|
967968
|3341.到达最后一个房间的最少时间I|中等|<a href="https://leetcode.cn/problems/find-minimum-time-to-reach-last-room-i/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/05/07/LeetCode%203341.%E5%88%B0%E8%BE%BE%E6%9C%80%E5%90%8E%E4%B8%80%E4%B8%AA%E6%88%BF%E9%97%B4%E7%9A%84%E6%9C%80%E5%B0%91%E6%97%B6%E9%97%B4I/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/147807022" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-minimum-time-to-reach-last-room-i/solutions/3672076/letmefly-3341dao-da-zui-hou-yi-ge-fang-j-3m6o/" target="_blank">LeetCode题解</a>|
968969
|3342.到达最后一个房间的最少时间II|中等|<a href="https://leetcode.cn/problems/find-minimum-time-to-reach-last-room-ii/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/05/09/LeetCode%203342.%E5%88%B0%E8%BE%BE%E6%9C%80%E5%90%8E%E4%B8%80%E4%B8%AA%E6%88%BF%E9%97%B4%E7%9A%84%E6%9C%80%E5%B0%91%E6%97%B6%E9%97%B4II/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/147835524" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-minimum-time-to-reach-last-room-ii/solutions/3672695/letmefly-3342dao-da-zui-hou-yi-ge-fang-j-qrh6/" target="_blank">LeetCode题解</a>|

0 commit comments

Comments
 (0)