开发者

find same node from two single linked list. Can't use hash, Can not be O(n^2) complexity

开发者 https://www.devze.com 2023-02-10 06:41 出处:网络
find same node from two single linked lists. Can\'t use hash, Can not be O(n^2) complexity. Please开发者_JS百科 give some hints.

find same node from two single linked lists. Can't use hash, Can not be O(n^2) complexity.

Please开发者_JS百科 give some hints. thank you so much.


Sort the two linked lists and then do a linear pass to find two nodes that are equal. This is 2*O(NlogN) + 2*O(N) = O(NlogN).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号