File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change 17
17
function findMaxRecursion ( arr , left , right ) {
18
18
const len = arr . length
19
19
20
- if ( len === 0 || ! arr ) return undefined
20
+ if ( len === 0 || ! arr ) {
21
+ return undefined
22
+ }
21
23
22
24
if ( left >= len || left < - len || right >= len || right < - len ) {
23
25
throw new Error ( 'Index out of range' )
24
26
}
25
27
26
- if ( left === right ) return arr [ left ]
28
+ if ( left === right ) {
29
+ return arr [ left ]
30
+ }
27
31
28
32
// x >> y == floor(x / pow(2, y))
29
33
const mid = ( left + right ) >> 1
30
34
31
- // Find the maximum of left and right
35
+ // n >> m is equivalent to floor(n / pow(2, m)), floor(n / 2) in this case
32
36
const leftMax = findMaxRecursion ( arr , left , mid )
33
37
const rightMax = findMaxRecursion ( arr , mid + 1 , right )
34
38
You can’t perform that action at this time.
0 commit comments