我相信最快的方式是最常用的方式:
时间复杂度为O(N)
let index_of e l =
let rec index_rec i = function
| [] -> raise Not_found
| hd::tl -> if hd = e then i else index_rec (i+1) tl
in
index_rec 0 l
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1439 次 |
| 最近记录: |