algorithm - Finding at least one common node in two lists with different lengths -
as title says, i'm looking efficient (not best) way find common node (one enough) in 2 lists.
what know lists is, have 2 lists different lengths , somewhere got common node. point common node is, both lists merge accord each other point.
i haven't written down code , won't because first need sure if way work. makes me unsure step 4:
- find out length of first list.
find out length of second list.
take bigger list , subtract smaller list (i call solution x).
- take longer list , run through first node x-th node ==> both lists should (!) have same number of nodes.
- now can run through both lists simultaneously till found common node.
do think it's ready coded? :)
Comments
Post a Comment