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

#滴滴面试题 #293

Open
MyLinChi opened this issue Sep 20, 2020 · 0 comments
Open

#滴滴面试题 #293

MyLinChi opened this issue Sep 20, 2020 · 0 comments

Comments

@MyLinChi
Copy link
Owner

实现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;
    }
};
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

No branches or pull requests

1 participant