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:

  1. find out length of first list.
  2. find out length of second list.

  3. take bigger list , subtract smaller list (i call solution x).

  4. take longer list , run through first node x-th node ==> both lists should (!) have same number of nodes.
  5. now can run through both lists simultaneously till found common node.

do think it's ready coded? :)


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -