param { number [ ] } houses return { number } function Rob ( houses ) { const len = houses . length ; if ( len <= 1 ) { return houses [ len - 1 ] ? houses [ len - 1 ] : 0 ; } let arr = [ houses [ 0 ] , Math . max ( houses [ 0 ] , houses [ 1 ] ) ] ; for ( let i = 2 ; i < len ; i ++ ) { arr [ i ] = Math . max ( arr [ i - 2 ] + houses [ i ] , arr [ i - 1 ] ) ; } return arr [ len - 1 ] ; } param { number [ ] } houses return { number } function Rob2 ( houses ) { if ( houses . length <= 1 ) { return houses [ 0 ] ? houses [ 0 ] : 0 ; } let arr1 = houses . slice ( 0 , - 1 ) ; let arr2 = houses . slice ( 1 ) ; return Math . max ( Rob ( arr1 ) , Rob ( arr2 ) ) ; } export { Rob , Rob2 } ;