#腾讯笔试# 第一题,又大佬能告诉我为什么我提交了几次在20%-100%之间浮动么😅
public ListNode[] solve (int m, ListNode a) {
// write code here
ListNode res[] = new ListNode[m];
ListNode next[] = new ListNode[m];
ListNode cur = a;
while (cur != null) {
int index = cur.val % m;
ListNode tmp = new ListNode(cur.val);
if (res[index] == null) {
res[index] = tmp;
next[index] = tmp;
}
else {
next[index].next = tmp;
next[index] = tmp;
}
cur = cur.next;
}
return res;
}
public ListNode[] solve (int m, ListNode a) {
// write code here
ListNode res[] = new ListNode[m];
ListNode next[] = new ListNode[m];
ListNode cur = a;
while (cur != null) {
int index = cur.val % m;
ListNode tmp = new ListNode(cur.val);
if (res[index] == null) {
res[index] = tmp;
next[index] = tmp;
}
else {
next[index].next = tmp;
next[index] = tmp;
}
cur = cur.next;
}
return res;
}
全部评论
相关推荐
04-05 17:19
杭州师范大学 管理培训生 点赞 评论 收藏
分享
点赞 评论 收藏
分享