俄罗斯方块 - 荷兰国际集团的数组 [英] Tetris-ing an array
本文介绍了俄罗斯方块 - 荷兰国际集团的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑下面的数组:
/网络/ htdocs中/ 1 /网站/ lib中/ abcdedd
/网络/ htdocs中/ 1 /网站/ conf目录/ XYZ
/网络/ htdocs中/ 1 /网站/ conf目录/ ABC / DEF
/网络/ htdocs中/ 1 /网站/ htdocs中/ XYZ
/网络/ htdocs中/ 1 /网站/ LIB2 / abcdedd
什么是检测的常见的基本路径的最短和最优雅的方式 - 在这种情况下,
/网络/ htdocs中/ 1 /网站/
和从阵列中的所有元素删除它?
的lib / abcdedd
CONF / XYZ
CONF / ABC / DEF
htdocs中/ XYZ
LIB2 / abcdedd
解决方案
写一个函数 longest_common_ preFIX
这两个字符串作为输入。然后,它适用于字符串任何以减少他们的共同preFIX。既然是联想和交换的顺序并不重要的结果。
这是一样的像例如加成或最大公约数其他二进制操作
Consider the following array:
/www/htdocs/1/sites/lib/abcdedd
/www/htdocs/1/sites/conf/xyz
/www/htdocs/1/sites/conf/abc/def
/www/htdocs/1/sites/htdocs/xyz
/www/htdocs/1/sites/lib2/abcdedd
what is the shortest and most elegant way of detecting the common base path - in this case
/www/htdocs/1/sites/
and removing it from all elements in the array?
lib/abcdedd
conf/xyz
conf/abc/def
htdocs/xyz
lib2/abcdedd
解决方案
Write a function longest_common_prefix
that takes two strings as input. Then apply it to the strings in any order to reduce them to their common prefix. Since it is associative and commutative the order doesn't matter for the result.
This is the same as for other binary operations like for example addition or greatest common divisor.
这篇关于俄罗斯方块 - 荷兰国际集团的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文