Fix Solution2 - 学号2023111432 #442
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
学号:2023111432
修改思路:
1.修正了数组大小错误
数组大小应该是26,而不是25
2.修复了循环逻辑错误导致的跨界访问
原本的循环会尝试获取s[lenth]处的字符
3. 修复计数数组初始化逻辑错误
原代码使用 num[s.charAt(i) - 'a']-- 错误记录负次数
修正为 num[s.charAt(i) - 'a']++ 正确记录正次数
在判断是否跳过重复字符前先减少剩余次数
确保弹出条件判断准确
测试结果:
12个测试用例全部通过
包括题目示例和多种边界情况
代码逻辑正确,性能符合要求