Skip to content

Commit a49aa6e

Browse files
committed
Adding snippet for Binary Search code
1 parent 7b1bb7f commit a49aa6e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<snippet>
2+
<content><![CDATA[
3+
ll bsearch(ll low, ll high)
4+
{
5+
6+
if (low >= high) {
7+
return low;
8+
}
9+
10+
ll mid = low + (high-low)/2;
11+
12+
bool condition = //test for set of 2 elements, no yes! if wrong, change mid
13+
14+
condition ? low = mid : high = mid-1 ; // maintain the invariant [low,high)
15+
// other case, low = mid+1 : high = mid , invariant is (low,high]
16+
return bsearch(low,high);
17+
}
18+
]]></content>
19+
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
20+
<tabTrigger>binary-search</tabTrigger>
21+
<!-- Optional: Set a scope to limit where the snippet will trigger -->
22+
<!-- <scope>source.python</scope> -->
23+
</snippet>

0 commit comments

Comments
 (0)