【发布时间】:2012-03-23 21:49:54
【问题描述】:
我有一个字符串数组(如示例所示)。我只是想找出其中最常见的。最常见的字符串定义为:- 如果 Apple Ipod touch 出现 10 次(比如说)而 Apple ipod 出现 8 次,那么我会说 Apple Ipod Touch 是所有元素中的主要/常见字符串。
Apple iPod touch, 8GB (with FaceTime Camera and Retina Display)
Aple Ipod Clasic 80gb 6th Generation Black
iPod classic 160GB - Silver
Apple 8GB iPod Touch
Apple Ipod Touch 8gb 4th Generation Mc540ll/a 8 Gb Newest Model
Apple iPod touch Black 4th Generation 8GB Touch Screen Wi-Fi MP3
Apple 8GB iPod touch�
Apple 8GB iPod touch MC540LL/A
Apple MC540LL/A - 8GB iPod Touch w/ Camera (4th Gen) (Newest Model)
Apple iPod Touch - 8 GB - Electronics
Apple iPod 8GB 4th Generation Black Touch
Apple iPod touch 8GB 4th Gen (Refurbished)
Apple Ipod Touch Digital Player - Apple Ios 5
Apple Ipod Touch 8G - White (4Th Gen)
Apple MC540LL/A iPod Touch 8GB (4th Generation)
(refurbished) Apple Ipod Touch 8gb (4th Generation)
Apple Ipod Touch 8Gb 4Th Generation
iPod Touch 8GB (4th Gen)
Apple Ipod Touch 32G - White (4Th Gen)
Apple iPod touch 8GB (4th Gen), White
Apple iPod touch White 4th Generation 8GB Touch Screen Wi-Fi MP3
Apple 32GB Black 4th Generation iPod Touch - MC544LL/A
Apple 8GB iPod touch�
Apple iPod touch 8GB - White - Electronics
Apple MC544LL/A - 32GB iPod Touch w/ Camera (4th Gen) (Newest Model)
那么,谁能建议我一些好的算法来做到这一点?问题是我没有任何标准/基准可以比较。我只需要比较所有元素之间,找出最常见的那个。这必须用 PHP 或 Javascript 实现。
希望我的问题很清楚。如果我在某处不清楚,请发表评论。
【问题讨论】:
-
所以你想要出现在最多行中的子字符串(可能只有完整的单词数)?因为那将是
Apple。还是您想要出现在多行中的最长子字符串? -
您要查找的字符串是整行还是其中的一部分?另外,您的搜索是否区分大小写?
-
字符串应尽可能长且不区分大小写
标签: php javascript algorithm