方法1:
f1 = 11 8 9 9 10 9 12 fx = eachRight(drop, isort f1, 1+rank f1) - til count f1 def findPrev(x): max iif(x<0, x, 00) def findNext(x): min iif(x>0, x, 00) table(f1, each(findPrev, fx) as f2, each(findNext, fx) as f3)
方法2,当vector比较大时,性能会更好一些:
f1 = 11 8 9 9 10 9 12 def dist(x, i) : ifirstHit(>, x.subarray(i:x.size()), x[i-1]) + 1 table(f1, each(dist{f1.reverse()}, size(f1)..1).replace!(0, 00) as f2, each(dist{f1}, 1..size(f1)).replace!(0, 00) as f3)