param { string [ ] } letters param { string } target return { string } function NextGreatestLetter ( letters , target ) { let left = 0 ; let right = letters . length - 1 ; while ( left < right ) { let mid = Math . floor ( left + ( right - left ) / 2 ) ; if ( letters [ mid ] === target && letters [ mid + 1 ] !== target ) { return letters [ mid + 1 ] ; } else if ( letters [ mid ] > target ) { right = mid ; } else { left = mid + 1 ; } } if ( letters [ left ] > target ) { return letters [ left ] ; } else { return letters [ 0 ] ; } } export { NextGreatestLetter } ;