Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

此题就是求两个单链表的第一个交点

Posted by team162 at 2012-02-26 14:30:02 on Problem 1330
int lca(int a, int b, int parent[])
{
    int ha = 0, hb = 0, x = a, y = b;
    while (parent[a]) ++ha, a = parent[a];
    while (parent[b]) ++hb, b = parent[b];
    while (ha > hb) x = parent[x], --ha;
    while (hb > ha) y = parent[y], --hb;
    while (x != y) x = parent[x], y = parent[y];
    return x;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator