当前位置:网站首页>An algorithm problem was encountered during the interview_ Find the mirrored word pairs in the dictionary

An algorithm problem was encountered during the interview_ Find the mirrored word pairs in the dictionary

2022-04-23 19:13:00 cjzcjl

Give me a dictionary , Find all mirrored pairs of words , If it appears in the dictionary abcd and dcba, Then list it

Personal thinking :

Use the dictionary tree , Each word is divided into a unit of each letter , Each element acts as a node . At the same time, every time you enter a word , Construct a mirror word and enter it :

Every time you add a word , If you find that before you add , Can find a fully matched path , And can run to the leaf node , It means that you have been added once by your previous mirror word , Together with their own and their own image output . In this way, you can find all the word pairs that match the pattern as long as you traverse the dictionary once .

版权声明
本文为[cjzcjl]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210600587886.html