Tetris-ing an array

后端 未结 16 1552
时光取名叫无心
时光取名叫无心 2021-01-30 15:38

Consider the following array:

/www/htdocs/1/sites/lib/abcdedd
/www/htdocs/1/sites/conf/xyz
/www/htdocs/1/sites/conf/abc/         


        
16条回答
  •  囚心锁ツ
    2021-01-30 16:14

    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.

提交回复
热议问题