如何在列表中找到第一个非零元素的索引

问题描述 投票:0回答:1

预期的结果将是数字索引

1

2
返回结果索引应为

let

。 如果答案避免使用序列操作员和循环,那将是很棒的。

	
没有sequence op op;
for

while

在香草OCAML中,我可以写:
arrays ocaml
1个回答
3
投票
class c = object (self) method f i = function | x::_ when x <> 0 -> i | _::xs -> self#f (i+1) xs | [] -> failwith "Got the answer from StackOverflow" end ;; (new c)#f 0 [0;0;1;2;0;4;5;6];;

	
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.