Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复Solution7的错误,并添加测试类。学号:2023120245 #374

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

eternalhappy
Copy link

@eternalhappy eternalhappy commented Dec 1, 2024

学号:2023120245
修正并查集大小:将并查集初始化的大小从 len - 1 改为 len,避免索引越界。
补全循环括号:为字符分组的 for 循环添加花括号,确保循环体包含所有必要的代码。
for (int i = 0; i < len; i++) {
int root = unionFind.find(i);
hashMap.computeIfAbsent(root, key -> new PriorityQueue<>()).offer(charArray[i]);
}
直接修改字符数组:在重组字符串时,直接修改原始字符数组,去除 StringBuilder 和多余的空格添加。
for (int i = 0; i < len; i++) {
int root = unionFind.find(i);
charArray[i] = hashMap.get(root).poll();
}
调整条件判断:将条件从 pairs.size() <= 1 改为 pairs.isEmpty(),确保包含单个索引对的情况被正确处理。
if (pairs.isEmpty()) {
return s;
}

@eternalhappy
Copy link
Author

测试结果
Snipaste_2024-12-01_19-59-40

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant