[Java interview with the record] programming problem

An array, in which all three numbers together as a combined output of 0;

Program: brute force, o (n ^ 3) the complexity of the worst answer ....

Option Two: first sorted and then loop through the array, do the following:

To i th element, the first number is A [i], the second digit is a [i + 1], the third digit is a [a.length-1];

They tested three digits, if more than 0, the third digital mobile forwardly 1, if less than 0, then the backward movement of the second digit 1, if equal, the three numbers into a certain form of the index set, then a cyclic I;

Time complexity: o (n ^ 2);

 

Given two lists of the head node, the node returns the intersection thereof;

A program: a brute force: given a chain, sequentially investigation it exists in another node in the list; time complexity o (mn); worst programs;

Scheme II: The two lists to find the end of the junction sequence, while recording their length, the same as if the end node, then the intersection, if the end node is different, the description does not intersect directly return null;

Intersecting the case: the longer chain rearward movement nodes k, k is the length difference between the two lists, then the pointer is moved backward while the two lists, when obtaining the same node, the node is an intersection point, return to;

Guess you like

Origin www.cnblogs.com/yeqingxue/p/11402563.html