很显然,将所有有联通关系的index都union成一个连通图,那么这些index对应的字符其实就可以任意调换顺序,想像成“冒泡法”就不难理解了。
将一个连通分量内的字符串抽取出来按照字典序重新排列,然后再依次放回这些index的位置,就是答案。
GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||
GeezerVison is showing github.com — LeetCode/Union_Find/1202.Smallest-String-With-Swaps at master · wisdompeak/LeetCode Expand file tree/ Copy path1202.Smallest-String-With-Swaps/Directory actionsMore optionsMore optionsDirectory actionsMore optionsMore options/ Copy path1202.Smallest-String-With-Swaps/Folders and files
很显然,将所有有联通关系的index都union成一个连通图,那么这些index对应的字符其实就可以任意调换顺序,想像成“冒泡法”就不难理解了。 将一个连通分量内的字符串抽取出来按照字典序重新排列,然后再依次放回这些index的位置,就是答案。 | |||||||||||||||||||||
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. | |||||||||||||||||||||