问数组中含有重复字符串算法。

excuseser 2004-07-20 05:07:27
在C社区里问过的但C的指针实在太好了,VB里怎么办?
设:
Array("ab" ,"bc","ac","ab","sr","ac","ad") 大量的无规律字符串数组,求一函数若有两个字符串相同,则返回1,反之为0,如上例,因"ac"重复出现,所以返回1。

ps:各项的长度是相等的。

谢谢大家,我很期待大家会有什么样精彩的算法。
不限语言,不限方法,只要快就行(时间复杂度,空间复杂度……该死的名词见鬼去吧!)
...全文
247 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
excuseser 2004-07-21
  • 打赏
  • 举报
回复
肯定不保证!欢迎 KiteGirl(小仙妹) 把方法贴出来啊。
KiteGirl 2004-07-20
  • 打赏
  • 举报
回复
你确认肯定是两个半角英文小写字符串吗?这很重要的!如果你确定这一点,我有一个特别快的算法。
mmcgzs 2004-07-20
  • 打赏
  • 举报
回复
佩服楼上的几位,牛。
rainstormmaster 2004-07-20
  • 打赏
  • 举报
回复
用集合加上错误处理比较好
leolan 2004-07-20
  • 打赏
  • 举报
回复
private function IsRepeat(v as variant) as boolean
on error resume next
dim o as new collection
dim i as integer

for i=lbound(v) to ubound(v)
o.add v(i),v(i)
if err then
IsRepeat = true
exit function
end if
next

end function
northwolves 2004-07-20
  • 打赏
  • 举报
回复
也可用集合处理:

Function existsame(ByRef x As Variant) As Integer
existsame = 0
On Error Resume Next
Dim i As Long, temp As New Collection
For i = 0 To UBound(x)
temp.Add x(i), x(i)
If temp.Count <= i Then
existsame = 1
Exit Function
End If
Next
End Function
northwolves 2004-07-20
  • 打赏
  • 举报
回复
Option Explicit

Private Sub Command1_Click()
Dim x
x = Array("ab", "bc", "ac", "ab", "sr", "ac", "ad")
MsgBox existsame(x)
End Sub
Function existsame(ByRef x As Variant) As Integer
existsame = 0
Dim i As Long
For i = 0 To UBound(x)
If UBound(Filter(x, x(i), , vbBinaryCompare)) > 0 Then
existsame = 1
Exit Function
End If
Next
End Function
northwolves 2004-07-20
  • 打赏
  • 举报
回复
Function existsame(ByRef x As Variant) As Boolean
Dim i As Long
For i = 0 To UBound(x)
If UBound(Filter(x, x(i), , vbBinaryCompare)) > 0 Then
existsame = True
Exit Function
End If
Next
End Function

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧