-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
实现10个线程并发执行,完成后返回结果
求解
使用CountDownLatch实现,每一个线程的run方法运行完毕调用一次countDown方法,然后在主线程中执行await方法等待所有子线程的执行结束。
/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
class Solution {
public:
/**
* 逆序
* @param head ListNode类 头结点
* @return ListNode类
*/
ListNode* reverseList(ListNode* head) {
// write code here
ListNode tmp(0),*res = &tmp;
for(ListNode* p = head->next;p;){
ListNode* tp = p->next;
p->next = res->next;
res->next = p;
p = tp;
}
return res->next;
}
};
Metadata
Metadata
Assignees
Labels
No labels