Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
11
Task/Binary-search/Jq/binary-search-1.jq
Normal file
11
Task/Binary-search/Jq/binary-search-1.jq
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
def binarySearch(value):
|
||||
# To avoid copying the array, simply pass in the current low and high offsets
|
||||
def binarySearch(low; high):
|
||||
if (high < low) then (-1 - low)
|
||||
else ( (low + high) / 2 | floor) as $mid
|
||||
| if (.[$mid] > value) then binarySearch(low; $mid-1)
|
||||
elif (.[$mid] < value) then binarySearch($mid+1; high)
|
||||
else $mid
|
||||
end
|
||||
end;
|
||||
binarySearch(0; length-1);
|
||||
1
Task/Binary-search/Jq/binary-search-2.jq
Normal file
1
Task/Binary-search/Jq/binary-search-2.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
[-1,-1.1,1,1,null,[null]] | binarySearch(1)
|
||||
Loading…
Add table
Add a link
Reference in a new issue